diff --git a/src/lib/editorManager.js b/src/lib/editorManager.js index 3a12f6184..8f28a2fca 100644 --- a/src/lib/editorManager.js +++ b/src/lib/editorManager.js @@ -1,6 +1,13 @@ import sidebarApps from "sidebarApps"; -import { indentUnit, language as languageFacet } from "@codemirror/language"; -import { search } from "@codemirror/search"; +import { + indentUnit, + language as languageFacet, + bracketMatching, + foldGutter, + indentOnInput, + syntaxHighlighting, +} from "@codemirror/language"; +import { highlightSelectionMatches, search } from "@codemirror/search"; import { Compartment, EditorSelection, @@ -19,6 +26,8 @@ import { keymap, lineNumbers, placeholder, + drawSelection, + highlightActiveLine, } from "@codemirror/view"; import { abbreviationTracker, @@ -62,7 +71,7 @@ import { } from "cm/modelist"; import createTouchSelectionMenu from "cm/touchSelectionMenu"; import "cm/supportedModes"; -import { autocompletion } from "@codemirror/autocomplete"; +import { autocompletion, closeBrackets } from "@codemirror/autocomplete"; import { serverCompletionSource } from "@codemirror/lsp-client"; import colorView from "cm/colorView"; import { @@ -937,6 +946,10 @@ async function EditorManager($header, $body) { const tagAutoRenameCompartment = new Compartment(); // Compartment for read-only toggling const readOnlyCompartment = new Compartment(); + // Compartment for brackets + const bracketCompartment = new Compartment(); + // Compartment for highlight + const highlightCompartment = new Compartment(); // Compartment for scrolling past the end of the file const scrollPastEndCompartment = new Compartment(); // Compartment for language mode (allows async loading/reconfigure) @@ -1267,6 +1280,44 @@ async function EditorManager($header, $body) { return enabled ? tagAutoRename() : []; }, }, + { + keys: ["autoCloseBrackets", "bracketMatching"], + compartments: [bracketCompartment], + build() { + const ext = []; + + if (appSettings.value.autoCloseBrackets !== false) { + ext.push(closeBrackets()); + } + + if (appSettings.value.bracketMatching !== false) { + ext.push(bracketMatching()); + } + + return ext; + }, + }, + { + keys: ["highlightActiveLine", "highlightSelectionMatches"], + compartments: [highlightCompartment], + build() { + const ext = []; + + if (appSettings.value.highlightActiveLine !== false) { + ext.push(highlightActiveLine()); + } + + if (appSettings.value.highlightSelectionMatches !== false) { + ext.push( + highlightSelectionMatches({ + minSelectionLength: 1, + }), + ); + } + + return ext; + }, + }, { keys: ["scrollPastEnd"], compartments: [scrollPastEndCompartment], @@ -3459,6 +3510,22 @@ async function EditorManager($header, $body) { applyOptions(["autoRenameTags"]); }); + appSettings.on("update:autoCloseBrackets", function () { + applyOptions(["autoCloseBrackets"]); + }); + + appSettings.on("update:bracketMatching", function () { + applyOptions(["bracketMatching"]); + }); + + appSettings.on("update:highlightActiveLine", function () { + applyOptions(["highlightActiveLine"]); + }); + + appSettings.on("update:highlightSelectionMatches", function () { + applyOptions(["highlightSelectionMatches"]); + }); + appSettings.on("update:scrollPastEnd", function () { applyOptions(["scrollPastEnd"]); });