-
Beta Was this translation helpful? Give feedback.
Answered by
jonpyt
Jul 26, 2024
Replies: 1 comment 1 reply
-
|
Folding for round brackets was disabled intentionally. I have though about changing this. In the mean time, if you want folding for round brackets, you can add a import { readOnlyCodeFolding, FoldingRangeProvider } from "prism-code-editor/code-folding"
import "prism-code-editor/code-folding.css"
const isMultiline = (str: string, start: number, end: number) => str.slice(start, end).includes("\n")
const roundBracketFolding: FoldingRangeProvider = editor => {
const matchBrackets = editor.extensions.matchBrackets
const folds: [number, number][] = []
const value = editor.value
if (matchBrackets) {
const { brackets, pairs } = matchBrackets
for (let i = 0, , l = pairs.length; i < l; i++) {
const other = pairs[i]!
if (
other > i &&
brackets[i][3] == "(" &&
isMultiline(value, brackets[i][1], brackets[other][1])
) {
folds.push([brackets[i][5], brackets[other][1]])
}
}
}
return folds
}
editor.addExtensions(readOnlyCodeFolding(roundBracketFolding)) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
ysk3a
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment


Folding for round brackets was disabled intentionally. I have though about changing this.
In the mean time, if you want folding for round brackets, you can add a
FoldingRangeProviderfor it like so: