Skip to content

fix: focus editor when creating a new page (rich mode)#3

Open
tmad4000 wants to merge 3 commits into
mainfrom
fix/new-file-focus
Open

fix: focus editor when creating a new page (rich mode)#3
tmad4000 wants to merge 3 commits into
mainfrom
fix/new-file-focus

Conversation

@tmad4000

Copy link
Copy Markdown
Owner

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-tab showEditor override 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-override showEditor focused unconditionally — the override lost that for rich mode.

Fix

  • New focusActiveEditor(tab) helper: focuses easyMDE.codemirror in rich mode, tab.editorEl in plain mode. It keys off settings.richEditorMode && tab.easyMDE rather than instance presence, because tab.easyMDE deliberately survives leaveRichMode (kept for undo history).
  • Called at the end of 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 new tests/new-file-focus.test.js (4 assertions, repo's source-assertion style).
  • Live CDP smoke against the running app: before New File 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

tmad4000 and others added 3 commits July 10, 2026 12:22
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant