Skip to content

Build your personal knowledge base with Trilium Notes

fix(code): set initial text

Elian Doran0c9be9291be3
diff --git a/apps/client/src/widgets/type_widgets/abstract_code_type_widget.ts b/apps/client/src/widgets/type_widgets/abstract_code_type_widget.ts
index 9614a3881a..7324868b0f 100644
--- a/apps/client/src/widgets/type_widgets/abstract_code_type_widget.ts
+++ b/apps/client/src/widgets/type_widgets/abstract_code_type_widget.ts
@@ -56,9 +56,13 @@ export default class AbstractCodeTypeWidget extends TypeWidget {
* @param {*} content the new content of the note.
*/
_update(note: { mime: string }, content: string) {
- // // CodeMirror breaks pretty badly on null, so even though it shouldn't happen (guarded by a consistency check)
- // // we provide fallback
- // this.codeEditor.setValue(content || "");
+ this.codeEditor.dispatch({
+ changes: {
+ from: 0,
+ to: this.codeEditor.state.doc.length,
+ insert: content || "",
+ }
+ })
// this.codeEditor.clearHistory();
// let info = CodeMirror.findModeByMIME(note.mime);