Repository navigation
fix(editor): focus Explorer-opened Markdown for find - #8083
Conversation
📝 WalkthroughWalkthroughUpdated 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/renderer/src/components/editor/rich-markdown-auto-focus.test.ts (1)
50-92: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider extracting shared test setup to reduce duplication.
Both new tests repeat the same
pendingFramecapture,vi.stubGlobalcalls forrequestAnimationFrame/cancelAnimationFrame/document, andcreateEditor(focus)pattern. A small helper (e.g.,setupFocusTest(activeElement)) would keep each test focused on its assertion and prevent the stubs from drifting.♻️ Optional helper extraction
+function setupFocusTest(activeElement: { closest: vi.Mock }) { + let pendingFrame: FrameRequestCallback = () => { + throw new Error('expected focus frame to be scheduled') + } + const focus = vi.fn() + vi.stubGlobal('requestAnimationFrame', (callback: FrameRequestCallback) => { + pendingFrame = callback + return 7 + }) + vi.stubGlobal('cancelAnimationFrame', vi.fn()) + vi.stubGlobal('document', { activeElement, body: {} }) + return { pendingFrame: () => pendingFrame, focus } +} + it('takes focus from the Explorer file row that opened the document', () => { - let pendingFrame: FrameRequestCallback = () => { - throw new Error('expected focus frame to be scheduled') - } - const focus = vi.fn() - const activeElement = { - closest: vi.fn().mockReturnValue({}) - } - vi.stubGlobal('requestAnimationFrame', (callback: FrameRequestCallback) => { - pendingFrame = callback - return 7 - }) - vi.stubGlobal('cancelAnimationFrame', vi.fn()) - vi.stubGlobal('document', { activeElement, body: {} }) - - autoFocusRichEditor(createEditor(focus), null) - pendingFrame(0) - - expect(activeElement.closest).toHaveBeenCalledWith('[data-file-explorer-row]') - expect(focus).toHaveBeenCalledWith('start', { scrollIntoView: false }) + const { pendingFrame, focus } = setupFocusTest({ + closest: vi.fn().mockReturnValue({}) + }) + autoFocusRichEditor(createEditor(focus), null) + pendingFrame(0) + expect(focus).toHaveBeenCalledWith('start', { scrollIntoView: false }) })
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 4a9b609f-949c-4093-a4e6-975e226ef12d
📥 Commits
Reviewing files that changed from the base of the PR and between e4c7aab and 06a04e519307e10a8730baacf961bf1748d29cee.
📒 Files selected for processing (3)
src/renderer/src/components/editor/rich-markdown-auto-focus.test.tssrc/renderer/src/components/editor/rich-markdown-auto-focus.tstests/e2e/markdown-explorer-find-focus.spec.ts
|
Taking a look! |
e98e5ae to
d68dcb3
Compare
|
Thanks for the fix! I rebased this onto current |
d68dcb3 to
aeec5c5
Compare
|
Thanks so much for this, @gatsby74 — focus Explorer-opened Markdown for find. Reviewed, rebased on latest |
…ines cap #8083 pushed RichMarkdownEditor.tsx to 404 counted lines against the 400-line .tsx cap, failing lint for every PR that merges current main. The Explorer find-focus request is self-contained, so it moves to its own hook.
…ry tab (#10437) * fix(runtime): stop the headless hydration repo gate from dropping every tab #9343 gated headless mobile-session hydration on the live repo list, but read it as `this.store?.getRepos?.() ?? []`. A store that cannot report repos then yields an empty set, which reads as "every repo is gone" and skips every parseable session key — so no tabs hydrate at all. It also called getRepos on every hydrate, including the hot floating-tab poll path that is contractually free of repo/provider inventory work. Resolve the inventory lazily and only for keys that parse to a repoId, and keep `null` (unavailable) distinct from an empty list (all repos really gone). An absent list now fails open; a known list still prunes as #9343 intended. Fixes 3 tests that have been failing on main since #9343 landed: orca-runtime-terminal-retirement (2) and orca-runtime (1). * refactor(editor): extract the pending-focus effect to clear the max-lines cap #8083 pushed RichMarkdownEditor.tsx to 404 counted lines against the 400-line .tsx cap, failing lint for every PR that merges current main. The Explorer find-focus request is self-contained, so it moves to its own hook.
Co-authored-by: Brennan Benson <[email protected]>
…ry tab (stablyai#10437) * fix(runtime): stop the headless hydration repo gate from dropping every tab stablyai#9343 gated headless mobile-session hydration on the live repo list, but read it as `this.store?.getRepos?.() ?? []`. A store that cannot report repos then yields an empty set, which reads as "every repo is gone" and skips every parseable session key — so no tabs hydrate at all. It also called getRepos on every hydrate, including the hot floating-tab poll path that is contractually free of repo/provider inventory work. Resolve the inventory lazily and only for keys that parse to a repoId, and keep `null` (unavailable) distinct from an empty list (all repos really gone). An absent list now fails open; a known list still prunes as stablyai#9343 intended. Fixes 3 tests that have been failing on main since stablyai#9343 landed: orca-runtime-terminal-retirement (2) and orca-runtime (1). * refactor(editor): extract the pending-focus effect to clear the max-lines cap stablyai#8083 pushed RichMarkdownEditor.tsx to 404 counted lines against the 400-line .tsx cap, failing lint for every PR that merges current main. The Explorer find-focus request is self-contained, so it moves to its own hook.
Summary
Opening a Markdown file from Explorer now hands keyboard focus to the rich Markdown editor, so the first Command/Ctrl+F opens rich Markdown search instead of doing nothing.
ELI5
Before, clicking a Markdown file in the sidebar left your cursor "stuck" on the file name, so pressing Find did nothing. Now the file you open is ready to type in and search right away.
Root cause & fix
When a Markdown file was opened from Explorer, focus stayed on the file row while the rich editor mounted. The editor's protective auto-focus guard treated that lingering Explorer focus like any unrelated control and refused to grab focus, so the first find shortcut fired outside the editor. The fix threads an explicit
focusEditorintent from Explorer file activation through a token-basedpendingEditorFocusRequestin the editor store, and givesautoFocusRichEditoraforceparam (defaultfalse) so only genuine Explorer opens claim focus — dialogs and other inputs stay protected.Evidence
Validated & rebased onto latest main during a bug-bash triage on 2026-07-23. Rebase was clean onto
origin/main.rich-markdown-auto-focus.test.ts,useFileExplorerHandlers.test.ts, andeditor.test.ts: 3 test files, 191 tests passed.oxlinton the 4 changed source files is clean (no warnings/errors).requires-appElectron E2E (tests/e2e/markdown-explorer-find-focus.spec.ts) covers the real open-then-find path; not run under vitest.Trade-offs
None — pure fix.
Regression risk
Low-to-zero.
autoFocusRichEditorgains aforceparam defaulting tofalse, so ordinary lazy mounts keep the prior neutral-focus guard byte-identical. New behavior is gated onoptions.focusEditor, set only by explicit Explorer file activation, and thependingEditorFocusRequestis consumed by matching token and cleared on file close / close-all / target-file close, avoiding stale focus steals. A negative test locks in the non-Explorer focus guard.Original fix by @gatsby74 (fixes #8078). Validated, rebased, and (where applicable) hardened via automated bug-bash review; original fix design preserved.