X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/dce51234527d1a0075f04d81b619e3d00e14ed3a..refs/pull/3617/head:/resources/js/code/setups.js diff --git a/resources/js/code/setups.js b/resources/js/code/setups.js index e1a150856..72700c9b6 100644 --- a/resources/js/code/setups.js +++ b/resources/js/code/setups.js @@ -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