Fix CodeMirror stability and dispatch errors

- Replaced dangerous custom dispatch override with EditorView.updateListener.
- Resolved 'Uncaught TypeError: child is undefined' by allowing CodeMirror to manage its own update cycle.
- Improved Svelte state syncing for new_content.
This commit is contained in:
Scott Idem
2026-01-08 14:56:19 -05:00
parent 66ddc9ace4
commit 2b21031beb

View File

@@ -86,6 +86,13 @@
theme_mode == 'dark' ? cm_modules.oneDark : cm_modules.EditorView.baseTheme(),
cm_modules.EditorView.contentAttributes.of({ spellcheck: 'true' }), // Enable spell check
// Sync document changes back to Svelte
cm_modules.EditorView.updateListener.of((update: any) => {
if (update.docChanged) {
new_content = update.state.doc.toString();
}
}),
// Conditional extensions based on props
editable ? cm_modules.EditorView.editable.of(true) : null,
readonly ? cm_modules.EditorState.readOnly.of(true) : null,
@@ -103,13 +110,7 @@
doc: content,
extensions: editor_extensions
}),
parent: editor_element,
dispatch: (transaction: any) => {
editorView.update([transaction]);
if (transaction.docChanged) {
new_content = editorView.state.doc.toString();
}
}
parent: editor_element
});
}