]> BookStack Code Mirror - bookstack/blobdiff - resources/js/code/setups.js
Fixed failing references after controller/file reshuffle
[bookstack] / resources / js / code / setups.js
index e1a150856f8236f4d6200db44888737d86a5770d..52b9cc199a5b8870eb80e30e11d408441c7e57bc 100644 (file)
@@ -1,30 +1,58 @@
+import {
+    EditorView, keymap, drawSelection, highlightActiveLine, dropCursor,
+    rectangularSelection, lineNumbers, highlightActiveLineGutter,
+} from '@codemirror/view';
+import {bracketMatching} from '@codemirror/language';
+import {
+    defaultKeymap, history, historyKeymap, indentWithTab,
+} from '@codemirror/commands';
+import {EditorState} from '@codemirror/state';
+import {getTheme} from './themes';
 
-import {keymap, highlightSpecialChars, 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 {EditorState} from "@codemirror/state"
-
-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),
     ];
-}
\ No newline at end of file
+}
+
+/**
+ * @param {Element} parentEl
+ * @return {*[]}
+ */
+export function editorExtensions(parentEl) {
+    return [
+        ...common(parentEl),
+        history(),
+        keymap.of([
+            ...defaultKeymap,
+            ...historyKeymap,
+            indentWithTab,
+        ]),
+        EditorView.lineWrapping,
+    ];
+}