Don't emit event if we did not get an active block (can happen with extremely large blocks, most likely because of slow syntax tree parsing)

This commit is contained in:
Jonatan Heyman 2023-01-19 23:41:39 +01:00
parent aa628a4f08
commit 6c1e89c5b0

View File

@ -285,14 +285,16 @@ const emitCursorChange = (editor) => ViewPlugin.fromClass(
if (update.selectionSet || langChange) { if (update.selectionSet || langChange) {
const cursorLine = getBlockLineFromPos(update.state, update.state.selection.main.head) const cursorLine = getBlockLineFromPos(update.state, update.state.selection.main.head)
const block = getActiveNoteBlock(update.state) const block = getActiveNoteBlock(update.state)
if (block) {
editor.element.dispatchEvent(new SelectionChangeEvent({ editor.element.dispatchEvent(new SelectionChangeEvent({
cursorLine, cursorLine,
language: block?.language.name, language: block.language.name,
languageAuto: block?.language.auto, languageAuto: block.language.auto,
})) }))
} }
} }
} }
}
) )
export const noteBlockExtension = (editor) => { export const noteBlockExtension = (editor) => {