From 14ed5afe7b89e9f5794f91315e9815e30de2ee0a Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Sun, 1 Feb 2026 03:59:49 +0100 Subject: [PATCH] Add useEffect to initialize CodeMirror editor in App.tsx --- src/App.tsx | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/App.tsx b/src/App.tsx index 0546225..0ddc3a2 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -203,6 +203,37 @@ export default function App() { } }, [selectedTextId]); + useEffect(() => { + const host = editorHostRef.current; + if (!host || editorViewRef.current) return; + const state = EditorState.create({ + doc: body, + extensions: [ + EditorView.lineWrapping, + history(), + keymap.of([...defaultKeymap, ...historyKeymap]), + lineNumbersCompartmentRef.current.of([]), + editableCompartmentRef.current.of(EditorView.editable.of(true)), + EditorView.updateListener.of((update) => { + if (!update.docChanged) return; + const value = update.state.doc.toString(); + editorValueRef.current = value; + setBody(value); + }) + ] + }); + const view = new EditorView({ + state, + parent: host + }); + editorViewRef.current = view; + editorValueRef.current = body; + return () => { + view.destroy(); + editorViewRef.current = null; + }; + }, []); + const isViewingHistory = viewingVersion !== null; const isDirty = !isViewingHistory && body !== lastPersistedBody; const hasText = body.trim().length > 0;