2023-04-18 17:20:02 -04:00
|
|
|
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';
|
2022-08-02 15:11:02 -04:00
|
|
|
|
2023-04-16 11:05:16 -04:00
|
|
|
/**
|
|
|
|
* @param {Element} parentEl
|
|
|
|
* @return {(Extension[]|{extension: Extension}|readonly Extension[])[]}
|
|
|
|
*/
|
|
|
|
function common(parentEl) {
|
2022-08-02 15:11:02 -04:00
|
|
|
return [
|
2023-04-16 11:05:16 -04:00
|
|
|
getTheme(parentEl),
|
2022-08-02 15:11:02 -04:00
|
|
|
lineNumbers(),
|
|
|
|
highlightActiveLineGutter(),
|
|
|
|
drawSelection(),
|
|
|
|
dropCursor(),
|
|
|
|
bracketMatching(),
|
|
|
|
rectangularSelection(),
|
|
|
|
highlightActiveLine(),
|
2023-04-16 11:05:16 -04:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Element} parentEl
|
|
|
|
* @return {*[]}
|
|
|
|
*/
|
2023-04-17 08:24:29 -04:00
|
|
|
export function viewerExtensions(parentEl) {
|
2023-04-16 11:05:16 -04:00
|
|
|
return [
|
|
|
|
...common(parentEl),
|
2022-08-02 15:11:02 -04:00
|
|
|
keymap.of([
|
|
|
|
...defaultKeymap,
|
|
|
|
]),
|
|
|
|
EditorState.readOnly.of(true),
|
|
|
|
];
|
2023-04-10 10:01:44 -04:00
|
|
|
}
|
|
|
|
|
2023-04-16 11:05:16 -04:00
|
|
|
/**
|
|
|
|
* @param {Element} parentEl
|
|
|
|
* @return {*[]}
|
|
|
|
*/
|
2023-04-17 08:24:29 -04:00
|
|
|
export function editorExtensions(parentEl) {
|
2023-04-10 10:01:44 -04:00
|
|
|
return [
|
2023-04-16 11:05:16 -04:00
|
|
|
...common(parentEl),
|
2023-04-10 10:01:44 -04:00
|
|
|
history(),
|
|
|
|
keymap.of([
|
|
|
|
...defaultKeymap,
|
|
|
|
...historyKeymap,
|
2023-04-18 08:41:28 -04:00
|
|
|
indentWithTab,
|
2023-04-10 10:01:44 -04:00
|
|
|
]),
|
2023-04-14 09:08:40 -04:00
|
|
|
EditorView.lineWrapping,
|
2023-04-10 10:01:44 -04:00
|
|
|
];
|
2023-04-18 17:20:02 -04:00
|
|
|
}
|