diff --git a/src/editor/editor.js b/src/editor/editor.js index 9a4a319f..e5b09552 100644 --- a/src/editor/editor.js +++ b/src/editor/editor.js @@ -48,6 +48,7 @@ export class HeynoteEditor { this.lineNumberCompartmentPre = new Compartment this.lineNumberCompartment = new Compartment this.foldGutterCompartment = new Compartment + this.readOnlyCompartment = new Compartment this.deselectOnCopy = keymap === "emacs" const state = EditorState.create({ @@ -60,6 +61,8 @@ export class HeynoteEditor { this.lineNumberCompartment.of(showLineNumberGutter ? [lineNumbers(), blockLineNumbers] : []), customSetup, this.foldGutterCompartment.of(showFoldGutter ? [foldGutter()] : []), + + this.readOnlyCompartment.of([]), this.themeCompartment.of(theme === "dark" ? heynoteDark : heynoteLight), heynoteBase, @@ -135,6 +138,12 @@ export class HeynoteEditor { this.view.focus() } + setReadOnly(readOnly) { + this.view.dispatch({ + effects: this.readOnlyCompartment.reconfigure(readOnly ? [EditorState.readOnly.of(true)] : []), + }) + } + setTheme(theme) { this.view.dispatch({ effects: this.themeCompartment.reconfigure(theme === "dark" ? heynoteDark : heynoteLight),