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