diff --git a/package.json b/package.json index 29a0930fb..81feeea3a 100644 --- a/package.json +++ b/package.json @@ -197,5 +197,10 @@ "@codemirror/state": "^6.6.0", "@codemirror/view": "^6.43.1" }, - "browserslist": "cover 100%" + "browserslist": "cover 100%", + "allowScripts": { + "@parcel/watcher@2.5.6": true, + "core-js@3.49.0": true, + "core-js-pure@3.49.0": true + } } diff --git a/src/cm/commandRegistry.js b/src/cm/commandRegistry.js index b06fd6909..43a0fb45e 100644 --- a/src/cm/commandRegistry.js +++ b/src/cm/commandRegistry.js @@ -53,7 +53,13 @@ import { toggleBlockComment, undo, } from "@codemirror/commands"; -import { indentUnit as indentUnitFacet } from "@codemirror/language"; +import { + foldAll, + foldCode, + indentUnit as indentUnitFacet, + unfoldAll, + unfoldCode, +} from "@codemirror/language"; import { closeLintPanel, forceLinting, @@ -946,6 +952,51 @@ function registerCoreCommands() { return simplifySelection(resolvedView); }, }); + addCommand({ + name: "foldCode", + description: "Fold the Lines that are selected (if possible)", + readOnly: true, + requiresView: true, + run(view) { + const resolvedView = resolveView(view); + if (!resolvedView) return false; + return foldCode(resolvedView); + }, + }); + addCommand({ + name: "unfoldCode", + description: "Unfold folded ranges on selected lines.", + readOnly: true, + requiresView: true, + run(view) { + const resolvedView = resolveView(view); + if (!resolvedView) return false; + return unfoldCode(resolvedView); + }, + }); + addCommand({ + name: "foldAll", + description: + "Fold all - top-level ranges usually depends on the syntax tree. It may not work reliably if the document isn't fully parsed (e.g., just initialized or too large to parse completely)", + readOnly: true, + requiresView: true, + run(view) { + const resolvedView = resolveView(view); + if (!resolvedView) return false; + return foldAll(resolvedView); + }, + }); + addCommand({ + name: "unfoldAll", + description: "Unfold all folded code.", + readOnly: true, + requiresView: true, + run(view) { + const resolvedView = resolveView(view); + if (!resolvedView) return false; + return unfoldAll(resolvedView); + }, + }); } function registerLspCommands() { diff --git a/src/lib/keyBindings.js b/src/lib/keyBindings.js index 958150d18..c80edd32f 100644 --- a/src/lib/keyBindings.js +++ b/src/lib/keyBindings.js @@ -517,6 +517,35 @@ const APP_BINDING_CONFIG = [ editorOnly: true, action: "format", }, + { + name: "foldCode", + description: "Fold code", + key: "Ctrl-Shift-[", + readOnly: true, + editorOnly: true, + }, + { + name: "unfoldCode", + description: "Unfold code", + key: "Ctrl-Shift-]", + readOnly: true, + editorOnly: true, + }, + { + name: "foldAll", + description: + "Fold all - top-level ranges usually depends on the syntax tree. It may not work reliably if the document isn't fully parsed (e.g., just initialized or too large to parse completely)", + key: "Ctrl-Alt-[", + readOnly: true, + editorOnly: true, + }, + { + name: "unfoldAll", + description: "Unfold all folded code", + key: "Ctrl-Alt-]", + readOnly: true, + editorOnly: true, + }, ]; const APP_KEY_BINDINGS = buildAppBindings(APP_BINDING_CONFIG);