]> BookStack Code Mirror - bookstack/blobdiff - resources/js/code/setups.js
CM6: Further fixes/improvements after testing
[bookstack] / resources / js / code / setups.js
index e1a150856f8236f4d6200db44888737d86a5770d..72700c9b6c56521f9a535e1e953296656929bc2e 100644 (file)
@@ -1,30 +1,54 @@
-
-import {keymap, highlightSpecialChars, drawSelection, highlightActiveLine, dropCursor,
+import {EditorView, keymap, drawSelection, highlightActiveLine, dropCursor,
     rectangularSelection, lineNumbers, highlightActiveLineGutter} from "@codemirror/view"
-import {defaultHighlightStyle, syntaxHighlighting, bracketMatching,
-     foldKeymap} 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,
-            ...foldKeymap,
         ]),
         EditorState.readOnly.of(true),
     ];
+}
+
+/**
+ * @param {Element} parentEl
+ * @return {*[]}
+ */
+export function editorExtensions(parentEl) {
+    return [
+        ...common(parentEl),
+        history(),
+        keymap.of([
+            ...defaultKeymap,
+            ...historyKeymap,
+            indentWithTab,
+        ]),
+        EditorView.lineWrapping,
+    ];
 }
\ No newline at end of file