]> BookStack Code Mirror - bookstack/blobdiff - resources/js/code/setups.js
CM6: Further fixes/improvements after testing
[bookstack] / resources / js / code / setups.js
index cd56261d3b845603421c7febeb545bf65b2a8828..72700c9b6c56521f9a535e1e953296656929bc2e 100644 (file)
@@ -1,47 +1,53 @@
-
-import {EditorView, keymap, highlightSpecialChars, drawSelection, highlightActiveLine, dropCursor,
+import {EditorView, keymap, drawSelection, highlightActiveLine, dropCursor,
     rectangularSelection, lineNumbers, highlightActiveLineGutter} from "@codemirror/view"
-import {syntaxHighlighting, bracketMatching} from "@codemirror/language"
-import {defaultKeymap, history, historyKeymap} from "@codemirror/commands"
+import {bracketMatching} from "@codemirror/language"
+import {defaultKeymap, history, historyKeymap, indentWithTab} from "@codemirror/commands"
 import {EditorState} from "@codemirror/state"
+import {getTheme} from "./themes";
 
-import {defaultLight} from "./themes";
-
-export function viewer() {
+/**
+ * @param {Element} parentEl
+ * @return {(Extension[]|{extension: Extension}|readonly Extension[])[]}
+ */
+function common(parentEl) {
     return [
+        getTheme(parentEl),
         lineNumbers(),
         highlightActiveLineGutter(),
-        highlightSpecialChars(),
-        history(),
         drawSelection(),
         dropCursor(),
-        syntaxHighlighting(defaultLight, {fallback: true}),
         bracketMatching(),
         rectangularSelection(),
         highlightActiveLine(),
+    ];
+}
+
+/**
+ * @param {Element} parentEl
+ * @return {*[]}
+ */
+export function viewerExtensions(parentEl) {
+    return [
+        ...common(parentEl),
         keymap.of([
             ...defaultKeymap,
-            ...historyKeymap,
         ]),
         EditorState.readOnly.of(true),
     ];
 }
 
-export function editor(language) {
+/**
+ * @param {Element} parentEl
+ * @return {*[]}
+ */
+export function editorExtensions(parentEl) {
     return [
-        lineNumbers(),
-        highlightActiveLineGutter(),
-        highlightSpecialChars(),
+        ...common(parentEl),
         history(),
-        drawSelection(),
-        dropCursor(),
-        syntaxHighlighting(defaultLight, {fallback: true}),
-        bracketMatching(),
-        rectangularSelection(),
-        highlightActiveLine(),
         keymap.of([
             ...defaultKeymap,
             ...historyKeymap,
+            indentWithTab,
         ]),
         EditorView.lineWrapping,
     ];