fix: focus editor when creating a new page (rich mode)#3
Open
tmad4000 wants to merge 3 commits into
Open
Conversation
The per-tab showEditor override only focused the plain-mode textarea; in rich mode (the default) the underlying textarea is hidden inside the EasyMDE wrapper, so Cmd+N / welcome-screen New File / sidebar inline-create left keyboard focus outside the editor. Add focusActiveEditor() which focuses the CodeMirror instance in rich mode and the textarea in plain mode, call it from showEditor and the rich/plain toggle. Verified via CDP smoke: activeElement lands inside .CodeMirror after New File. Closes markdown-reader-zi2 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Jacob: "when I create a new page it should focus." Creating a new page (Cmd+N / File > New, the welcome-screen New File button, or sidebar inline-create which opens the file with
forceEdit) left keyboard focus outside the editor — the next keystroke went nowhere.Root cause
Every new-file path funnels through
showEditor. The per-tabshowEditoroverride only focused the plain-mode textarea; in rich mode (the default) the underlying textarea is hidden inside the EasyMDE wrapper, so focusing it was a no-op and focus stayed on<body>. The original pre-overrideshowEditorfocused unconditionally — the override lost that for rich mode.Fix
focusActiveEditor(tab)helper: focuseseasyMDE.codemirrorin rich mode,tab.editorElin plain mode. It keys offsettings.richEditorMode && tab.easyMDErather than instance presence, becausetab.easyMDEdeliberately survivesleaveRichMode(kept for undo history).showEditor(both modes) and from the rich/plain toggle button (entering rich mode via the button never focused either).Verification
npm test— 63/63 pass, including newtests/new-file-focus.test.js(4 assertions, repo's source-assertion style).document.activeElement=BODY; after, it is inside.CodeMirror({"richMode":true,"inCodeMirror":true,"focused":true}).Beads: closes markdown-reader-zi2. Note for #2 (Milkdown): its editor will need the same focus handling (markdown-reader-dcy).
🤖 Generated with Claude Code