From 14e1f40ecf531ea391fb5161076868852c1b5d31 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Fri, 13 Mar 2026 21:53:57 +0100 Subject: [PATCH] Add logic to focus editor after creating new text --- src/App.tsx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/App.tsx b/src/App.tsx index af0cbe4..588f708 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -268,6 +268,7 @@ export default function App() { const historySnapshotRef = useRef(null); const recentOpenRef = useRef(new Map()); const searchRestoreSplitRef = useRef(null); + const pendingEditorFocusRef = useRef(false); const ignoreTextBlurRef = useRef(false); const ignoreFolderBlurRef = useRef(false); @@ -663,6 +664,17 @@ export default function App() { view.requestMeasure(); }, [markdownPreview, splitView, textSize, sidebarCollapsed, historyOpen]); + useEffect(() => { + if (!pendingEditorFocusRef.current) return; + if (!selectedTextId || !editorReady || isViewingHistory) return; + if (markdownPreview && !splitView) return; + + pendingEditorFocusRef.current = false; + window.requestAnimationFrame(() => { + editorViewRef.current?.focus(); + }); + }, [editorReady, isViewingHistory, markdownPreview, selectedTextId, splitView]); + const refreshTexts = useCallback(async () => { setLoadingTexts(true); @@ -989,6 +1001,8 @@ export default function App() { const handleNewText = useCallback(async () => { const { textId } = await createText(DEFAULT_TITLE, "", null); await refreshTexts(); + pendingEditorFocusRef.current = true; + setMarkdownPreview(false); setSelectedTextId(textId); }, [refreshTexts]);