Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/components/CodeEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const CodeEditor = () => {
setCurrentDocument(document);
setContent(document.content);

// Update editor content
// Update editor content and focus
if (editorView) {
editorView.dispatch({
changes: {
Expand All @@ -87,6 +87,9 @@ const CodeEditor = () => {
insert: document.content
}
});

// Focus the editor after switching documents
editorView.focus();
}
}
};
Expand All @@ -105,7 +108,7 @@ const CodeEditor = () => {
setCurrentDocument(newDoc);
setContent(newDoc.content);

// Update editor content
// Update editor content and focus
if (editorView) {
editorView.dispatch({
changes: {
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
Loading