chore(code): reintroduce read-only mode

This commit is contained in:
Elian Doran 2025-05-11 18:42:56 +03:00
parent 49838fb773
commit 3e5e19b8a5
No known key found for this signature in database
2 changed files with 7 additions and 2 deletions

View File

@ -39,7 +39,7 @@ export default class ReadOnlyCodeTypeWidget extends AbstractCodeTypeWidget {
this.show(); this.show();
} }
getExtraOpts(): Partial<CodeMirrorOpts> { getExtraOpts() {
return { return {
readOnly: true readOnly: true
}; };

View File

@ -1,7 +1,7 @@
import { defaultKeymap, history, historyKeymap } from "@codemirror/commands"; import { defaultKeymap, history, historyKeymap } from "@codemirror/commands";
import { EditorView, highlightActiveLine, keymap, lineNumbers, placeholder, ViewUpdate, type EditorViewConfig } from "@codemirror/view"; import { EditorView, highlightActiveLine, keymap, lineNumbers, placeholder, ViewUpdate, type EditorViewConfig } from "@codemirror/view";
import { defaultHighlightStyle, StreamLanguage, syntaxHighlighting, indentUnit, bracketMatching, foldGutter } from "@codemirror/language"; import { defaultHighlightStyle, StreamLanguage, syntaxHighlighting, indentUnit, bracketMatching, foldGutter } from "@codemirror/language";
import { Compartment, type Extension } from "@codemirror/state"; import { Compartment, EditorState, type Extension } from "@codemirror/state";
import { highlightSelectionMatches } from "@codemirror/search"; import { highlightSelectionMatches } from "@codemirror/search";
import { vim } from "@replit/codemirror-vim"; import { vim } from "@replit/codemirror-vim";
import byMimeType from "./syntax_highlighting.js"; import byMimeType from "./syntax_highlighting.js";
@ -14,6 +14,7 @@ export interface EditorConfig {
placeholder?: string; placeholder?: string;
lineWrapping?: boolean; lineWrapping?: boolean;
vimKeybindings?: boolean; vimKeybindings?: boolean;
readOnly?: boolean;
onContentChanged?: ContentChangedListener; onContentChanged?: ContentChangedListener;
} }
@ -51,6 +52,10 @@ export default class CodeMirror extends EditorView {
]) ])
] ]
if (config.readOnly) {
extensions.push(EditorState.readOnly.of(true));
}
if (config.placeholder) { if (config.placeholder) {
extensions.push(placeholder(config.placeholder)); extensions.push(placeholder(config.placeholder));
} }