Fix error on startup when cursor is moved to the end of a large buffer (caused by the syntaxTree not being parsed in time)

This commit is contained in:
Jonatan Heyman 2024-07-14 14:42:21 +02:00
parent 971f406720
commit 8626dcc141

View File

@ -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";
@ -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},