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:
@@ -86,6 +86,13 @@
|
|||||||
theme_mode == 'dark' ? cm_modules.oneDark : cm_modules.EditorView.baseTheme(),
|
theme_mode == 'dark' ? cm_modules.oneDark : cm_modules.EditorView.baseTheme(),
|
||||||
cm_modules.EditorView.contentAttributes.of({ spellcheck: 'true' }), // Enable spell check
|
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
|
// Conditional extensions based on props
|
||||||
editable ? cm_modules.EditorView.editable.of(true) : null,
|
editable ? cm_modules.EditorView.editable.of(true) : null,
|
||||||
readonly ? cm_modules.EditorState.readOnly.of(true) : null,
|
readonly ? cm_modules.EditorState.readOnly.of(true) : null,
|
||||||
@@ -103,13 +110,7 @@
|
|||||||
doc: content,
|
doc: content,
|
||||||
extensions: editor_extensions
|
extensions: editor_extensions
|
||||||
}),
|
}),
|
||||||
parent: editor_element,
|
parent: editor_element
|
||||||
dispatch: (transaction: any) => {
|
|
||||||
editorView.update([transaction]);
|
|
||||||
if (transaction.docChanged) {
|
|
||||||
new_content = editorView.state.doc.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user