Skip to content

Commit

Permalink
Fix error on startup when cursor is moved to the end of a large buffe…
Browse files Browse the repository at this point in the history
…r (caused by the syntaxTree not being parsed in time)
  • Loading branch information
heyman committed Jul 14, 2024
1 parent 971f406 commit 1b7f882
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/editor/editor.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Annotation, EditorState, Compartment, Facet } from "@codemirror/state"
import { EditorView, keymap, drawSelection, ViewPlugin, lineNumbers } from "@codemirror/view"
import { indentUnit, forceParsing, foldGutter } from "@codemirror/language"
import { indentUnit, forceParsing, foldGutter, ensureSyntaxTree } from "@codemirror/language"
import { markdown } from "@codemirror/lang-markdown"
import { closeBrackets } from "@codemirror/autocomplete";

Expand Down Expand Up @@ -116,6 +116,10 @@ export class HeynoteEditor {
parent: element,
})

// Ensure we have a parsed syntax tree when buffer is loaded. This prevents errors for large buffers
// when moving the cursor to the end of the buffer when the program starts
ensureSyntaxTree(state, state.doc.length, 5000)

if (focus) {
this.view.dispatch({
selection: {anchor: this.view.state.doc.length, head: this.view.state.doc.length},
Expand Down

0 comments on commit 1b7f882

Please sign in to comment.