Skip to content

Commit

Permalink
Add Editor.setReadOnly() method
Browse files Browse the repository at this point in the history
  • Loading branch information
heyman committed Dec 27, 2023
1 parent 3c47641 commit 2b9d6b7
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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,
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 2b9d6b7

Please sign in to comment.