From 610cb54806f6738c70fde66bbdff6cbb454bfb27 Mon Sep 17 00:00:00 2001 From: UnschooledGamer <76094069+UnschooledGamer@users.noreply.github.com> Date: Tue, 23 Jun 2026 22:00:44 +0530 Subject: [PATCH 1/9] feat(keybind): add code folds keybinds --- src/cm/commandRegistry.js | 46 ++++++++++++++++++++++++++++++++++++++- src/lib/keyBindings.js | 31 ++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/src/cm/commandRegistry.js b/src/cm/commandRegistry.js index b06fd6909..e1372c6f9 100644 --- a/src/cm/commandRegistry.js +++ b/src/cm/commandRegistry.js @@ -53,7 +53,7 @@ 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 +946,50 @@ function registerCoreCommands() { return simplifySelection(resolvedView); }, }); + addCommand({ + name: "foldCode", + description: "Fold the Lines that are selected (if possible)", + readOnly: false, + 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: false, + 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: false, + requiresView: true, + run(view) { + const resolvedView = resolveView(view); + if (!resolvedView) return false; + return foldAll(resolvedView); + } + }); + addCommand({ + name: "unfoldAll", + description: "Unfold all folded code.", + readOnly: false, + 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..d8cedb2b5 100644 --- a/src/lib/keyBindings.js +++ b/src/lib/keyBindings.js @@ -517,6 +517,34 @@ const APP_BINDING_CONFIG = [ editorOnly: true, action: "format", }, + { + name: "foldCode", + description: "Fold code", + key: "Ctrl-Shift-[", + readOnly: false, + editorOnly: true, + }, + { + name: "unfoldCode", + description: "Unfold code", + key: "Ctrl-Shift-]", + readOnly: false, + editorOnly: true, + }, + { + name: "foldAll", + description: "Folding 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: false, + editorOnly: true, + }, + { + name: "unfoldAll", + description: "Unfold all folded code", + key: "Ctrl-Alt-]", + readOnly: false, + editorOnly: true, + } ]; const APP_KEY_BINDINGS = buildAppBindings(APP_BINDING_CONFIG); @@ -589,6 +617,7 @@ function buildCodemirrorKeyBindings(appBindings) { const comboMap = new Map(); for (const binding of KEYMAP_SOURCES) { + console.log(binding) const baseCombos = new Set(); pushCommandCombo(binding.run, binding.key, "win", baseCombos); @@ -615,6 +644,7 @@ function buildCodemirrorKeyBindings(appBindings) { } const result = {}; + console.log("comboMap", comboMap) for (const [name, combos] of comboMap.entries()) { if (!combos.size || appBindings[name]) continue; result[name] = { @@ -626,6 +656,7 @@ function buildCodemirrorKeyBindings(appBindings) { editorOnly: true, }; } + console.log("result", result) return result; function pushCommandCombo(commandFn, key, platform, baseCombos) { From 34fe4ffcb639e4066f192c2854a8da256ec44d7f Mon Sep 17 00:00:00 2001 From: UnschooledGamer <76094069+UnschooledGamer@users.noreply.github.com> Date: Tue, 23 Jun 2026 22:03:18 +0530 Subject: [PATCH 2/9] update desc of foldAll --- src/lib/keyBindings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/keyBindings.js b/src/lib/keyBindings.js index d8cedb2b5..e99416cc8 100644 --- a/src/lib/keyBindings.js +++ b/src/lib/keyBindings.js @@ -533,7 +533,7 @@ const APP_BINDING_CONFIG = [ }, { name: "foldAll", - description: "Folding 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)", + 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: false, editorOnly: true, From d40e5f70585c4f4e522e1607a9fc08082406c901 Mon Sep 17 00:00:00 2001 From: UnschooledGamer <76094069+UnschooledGamer@users.noreply.github.com> Date: Tue, 23 Jun 2026 22:03:42 +0530 Subject: [PATCH 3/9] add: allowScripts in package.json --- package.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 + } } From d6befa6895e12e195ea423d1045b3d78c8c15de9 Mon Sep 17 00:00:00 2001 From: UnschooledGamer <76094069+UnschooledGamer@users.noreply.github.com> Date: Tue, 23 Jun 2026 22:11:25 +0530 Subject: [PATCH 4/9] chore: fmt changes --- src/cm/commandRegistry.js | 19 +++++++++++++------ src/lib/keyBindings.js | 11 ++++++----- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/cm/commandRegistry.js b/src/cm/commandRegistry.js index e1372c6f9..efeb83a30 100644 --- a/src/cm/commandRegistry.js +++ b/src/cm/commandRegistry.js @@ -53,7 +53,13 @@ import { toggleBlockComment, undo, } from "@codemirror/commands"; -import { foldAll, foldCode, indentUnit as indentUnitFacet, unfoldAll, unfoldCode } from "@codemirror/language"; +import { + foldAll, + foldCode, + indentUnit as indentUnitFacet, + unfoldAll, + unfoldCode, +} from "@codemirror/language"; import { closeLintPanel, forceLinting, @@ -955,7 +961,7 @@ function registerCoreCommands() { const resolvedView = resolveView(view); if (!resolvedView) return false; return foldCode(resolvedView); - } + }, }); addCommand({ name: "unfoldCode", @@ -966,18 +972,19 @@ function registerCoreCommands() { 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)", + 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: false, requiresView: true, run(view) { const resolvedView = resolveView(view); if (!resolvedView) return false; return foldAll(resolvedView); - } + }, }); addCommand({ name: "unfoldAll", @@ -988,7 +995,7 @@ function registerCoreCommands() { const resolvedView = resolveView(view); if (!resolvedView) return false; return unfoldAll(resolvedView); - } + }, }); } diff --git a/src/lib/keyBindings.js b/src/lib/keyBindings.js index e99416cc8..6a0b74ef9 100644 --- a/src/lib/keyBindings.js +++ b/src/lib/keyBindings.js @@ -533,7 +533,8 @@ const APP_BINDING_CONFIG = [ }, { 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)", + 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: false, editorOnly: true, @@ -544,7 +545,7 @@ const APP_BINDING_CONFIG = [ key: "Ctrl-Alt-]", readOnly: false, editorOnly: true, - } + }, ]; const APP_KEY_BINDINGS = buildAppBindings(APP_BINDING_CONFIG); @@ -617,7 +618,7 @@ function buildCodemirrorKeyBindings(appBindings) { const comboMap = new Map(); for (const binding of KEYMAP_SOURCES) { - console.log(binding) + console.log(binding); const baseCombos = new Set(); pushCommandCombo(binding.run, binding.key, "win", baseCombos); @@ -644,7 +645,7 @@ function buildCodemirrorKeyBindings(appBindings) { } const result = {}; - console.log("comboMap", comboMap) + console.log("comboMap", comboMap); for (const [name, combos] of comboMap.entries()) { if (!combos.size || appBindings[name]) continue; result[name] = { @@ -656,7 +657,7 @@ function buildCodemirrorKeyBindings(appBindings) { editorOnly: true, }; } - console.log("result", result) + console.log("result", result); return result; function pushCommandCombo(commandFn, key, platform, baseCombos) { From 9d8f170002eb1ac42a4e63094dbdf755e3ac6ec9 Mon Sep 17 00:00:00 2001 From: Emmanuel Lobo <76094069+UnschooledGamer@users.noreply.github.com> Date: Tue, 23 Jun 2026 23:09:16 +0530 Subject: [PATCH 5/9] Update commandRegistry.js --- src/cm/commandRegistry.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cm/commandRegistry.js b/src/cm/commandRegistry.js index efeb83a30..43a0fb45e 100644 --- a/src/cm/commandRegistry.js +++ b/src/cm/commandRegistry.js @@ -955,7 +955,7 @@ function registerCoreCommands() { addCommand({ name: "foldCode", description: "Fold the Lines that are selected (if possible)", - readOnly: false, + readOnly: true, requiresView: true, run(view) { const resolvedView = resolveView(view); @@ -966,7 +966,7 @@ function registerCoreCommands() { addCommand({ name: "unfoldCode", description: "Unfold folded ranges on selected lines.", - readOnly: false, + readOnly: true, requiresView: true, run(view) { const resolvedView = resolveView(view); @@ -978,7 +978,7 @@ function registerCoreCommands() { 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: false, + readOnly: true, requiresView: true, run(view) { const resolvedView = resolveView(view); @@ -989,7 +989,7 @@ function registerCoreCommands() { addCommand({ name: "unfoldAll", description: "Unfold all folded code.", - readOnly: false, + readOnly: true, requiresView: true, run(view) { const resolvedView = resolveView(view); From 265d63d9d82731c27d8248fe472ed04edbba7f78 Mon Sep 17 00:00:00 2001 From: Emmanuel Lobo <76094069+UnschooledGamer@users.noreply.github.com> Date: Tue, 23 Jun 2026 23:10:50 +0530 Subject: [PATCH 6/9] Update keyBindings.js --- src/lib/keyBindings.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/keyBindings.js b/src/lib/keyBindings.js index 6a0b74ef9..a0f20cad7 100644 --- a/src/lib/keyBindings.js +++ b/src/lib/keyBindings.js @@ -521,14 +521,14 @@ const APP_BINDING_CONFIG = [ name: "foldCode", description: "Fold code", key: "Ctrl-Shift-[", - readOnly: false, + readOnly: true, editorOnly: true, }, { name: "unfoldCode", description: "Unfold code", key: "Ctrl-Shift-]", - readOnly: false, + readOnly: true, editorOnly: true, }, { @@ -536,14 +536,14 @@ const APP_BINDING_CONFIG = [ 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: false, + readOnly: true, editorOnly: true, }, { name: "unfoldAll", description: "Unfold all folded code", key: "Ctrl-Alt-]", - readOnly: false, + readOnly: true, editorOnly: true, }, ]; From 909f5785ff7907d71691f140917e2bd88d432f27 Mon Sep 17 00:00:00 2001 From: Emmanuel Lobo <76094069+UnschooledGamer@users.noreply.github.com> Date: Tue, 23 Jun 2026 23:12:07 +0530 Subject: [PATCH 7/9] Update keyBindings.js --- src/lib/keyBindings.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib/keyBindings.js b/src/lib/keyBindings.js index a0f20cad7..9e5d2a827 100644 --- a/src/lib/keyBindings.js +++ b/src/lib/keyBindings.js @@ -618,7 +618,6 @@ function buildCodemirrorKeyBindings(appBindings) { const comboMap = new Map(); for (const binding of KEYMAP_SOURCES) { - console.log(binding); const baseCombos = new Set(); pushCommandCombo(binding.run, binding.key, "win", baseCombos); From 66ba8c6215ecc95788af8e1a0da52510cc701fdd Mon Sep 17 00:00:00 2001 From: Emmanuel Lobo <76094069+UnschooledGamer@users.noreply.github.com> Date: Tue, 23 Jun 2026 23:12:46 +0530 Subject: [PATCH 8/9] Update keyBindings.js --- src/lib/keyBindings.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib/keyBindings.js b/src/lib/keyBindings.js index 9e5d2a827..6ce60ff18 100644 --- a/src/lib/keyBindings.js +++ b/src/lib/keyBindings.js @@ -644,7 +644,6 @@ function buildCodemirrorKeyBindings(appBindings) { } const result = {}; - console.log("comboMap", comboMap); for (const [name, combos] of comboMap.entries()) { if (!combos.size || appBindings[name]) continue; result[name] = { From 1ea54e48d7e294ae3de410e325efbe2f31f777ab Mon Sep 17 00:00:00 2001 From: Emmanuel Lobo <76094069+UnschooledGamer@users.noreply.github.com> Date: Tue, 23 Jun 2026 23:13:45 +0530 Subject: [PATCH 9/9] Update keyBindings.js --- src/lib/keyBindings.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib/keyBindings.js b/src/lib/keyBindings.js index 6ce60ff18..c80edd32f 100644 --- a/src/lib/keyBindings.js +++ b/src/lib/keyBindings.js @@ -655,7 +655,6 @@ function buildCodemirrorKeyBindings(appBindings) { editorOnly: true, }; } - console.log("result", result); return result; function pushCommandCombo(commandFn, key, platform, baseCombos) {