From cb35b69166de739c7b764a29c0e3f1950490c90b Mon Sep 17 00:00:00 2001 From: Aitect Date: Tue, 5 Aug 2025 17:45:26 +0000 Subject: [PATCH] fix: focus after document changing --- src/components/CodeEditor.jsx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/components/CodeEditor.jsx b/src/components/CodeEditor.jsx index 46dbf36..390c94b 100644 --- a/src/components/CodeEditor.jsx +++ b/src/components/CodeEditor.jsx @@ -78,7 +78,7 @@ const CodeEditor = () => { setCurrentDocument(document); setContent(document.content); - // Update editor content + // Update editor content and focus if (editorView) { editorView.dispatch({ changes: { @@ -87,6 +87,9 @@ const CodeEditor = () => { insert: document.content } }); + + // Focus the editor after switching documents + editorView.focus(); } } }; @@ -105,7 +108,7 @@ const CodeEditor = () => { setCurrentDocument(newDoc); setContent(newDoc.content); - // Update editor content + // Update editor content and focus if (editorView) { editorView.dispatch({ changes: { @@ -114,6 +117,9 @@ const CodeEditor = () => { insert: newDoc.content } }); + + // Focus the editor after creating a new document + editorView.focus(); } } catch (error) { console.error('Error creating document:', error); @@ -238,6 +244,11 @@ const CodeEditor = () => { setEditorView(view); setContent(currentDocument.content); + // Focus the editor when it's first created or when switching documents + setTimeout(() => { + view.focus(); + }, 0); + // Cleanup return () => { view.destroy();