2023-04-15 14:35:41 +00:00
|
|
|
import {EditorView, keymap, drawSelection, highlightActiveLine, dropCursor,
|
2022-08-02 19:11:02 +00:00
|
|
|
rectangularSelection, lineNumbers, highlightActiveLineGutter} from "@codemirror/view"
|
2023-04-16 15:05:16 +00:00
|
|
|
import {bracketMatching} from "@codemirror/language"
|
2023-04-18 12:41:28 +00:00
|
|
|
import {defaultKeymap, history, historyKeymap, indentWithTab} from "@codemirror/commands"
|
2022-08-02 19:11:02 +00:00
|
|
|
import {EditorState} from "@codemirror/state"
|
2023-04-16 15:05:16 +00:00
|
|
|
import {getTheme} from "./themes";
|
2022-08-02 19:11:02 +00:00
|
|
|
|
2023-04-16 15:05:16 +00:00
|
|
|
/**
|
|
|
|
* @param {Element} parentEl
|
|
|
|
* @return {(Extension[]|{extension: Extension}|readonly Extension[])[]}
|
|
|
|
*/
|
|
|
|
function common(parentEl) {
|
2022-08-02 19:11:02 +00:00
|
|
|
return [
|
2023-04-16 15:05:16 +00:00
|
|
|
getTheme(parentEl),
|
2022-08-02 19:11:02 +00:00
|
|
|
lineNumbers(),
|
|
|
|
highlightActiveLineGutter(),
|
|
|
|
drawSelection(),
|
|
|
|
dropCursor(),
|
|
|
|
bracketMatching(),
|
|
|
|
rectangularSelection(),
|
|
|
|
highlightActiveLine(),
|
2023-04-16 15:05:16 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Element} parentEl
|
|
|
|
* @return {*[]}
|
|
|
|
*/
|
2023-04-17 12:24:29 +00:00
|
|
|
export function viewerExtensions(parentEl) {
|
2023-04-16 15:05:16 +00:00
|
|
|
return [
|
|
|
|
...common(parentEl),
|
2022-08-02 19:11:02 +00:00
|
|
|
keymap.of([
|
|
|
|
...defaultKeymap,
|
|
|
|
]),
|
|
|
|
EditorState.readOnly.of(true),
|
|
|
|
];
|
2023-04-10 14:01:44 +00:00
|
|
|
}
|
|
|
|
|
2023-04-16 15:05:16 +00:00
|
|
|
/**
|
|
|
|
* @param {Element} parentEl
|
|
|
|
* @return {*[]}
|
|
|
|
*/
|
2023-04-17 12:24:29 +00:00
|
|
|
export function editorExtensions(parentEl) {
|
2023-04-10 14:01:44 +00:00
|
|
|
return [
|
2023-04-16 15:05:16 +00:00
|
|
|
...common(parentEl),
|
2023-04-10 14:01:44 +00:00
|
|
|
history(),
|
|
|
|
keymap.of([
|
|
|
|
...defaultKeymap,
|
|
|
|
...historyKeymap,
|
2023-04-18 12:41:28 +00:00
|
|
|
indentWithTab,
|
2023-04-10 14:01:44 +00:00
|
|
|
]),
|
2023-04-14 13:08:40 +00:00
|
|
|
EditorView.lineWrapping,
|
2023-04-10 14:01:44 +00:00
|
|
|
];
|
2022-08-02 19:11:02 +00:00
|
|
|
}
|