Repository navigation
fix(editor): preserve Markdown focus handoffs - #10618
Conversation
📝 WalkthroughWalkthroughEditor focus requests now include a view-state identifier, token, and 30-second expiration timestamp. Rich markdown editors pass the view-state identifier to pending-focus handling, which matches requests to the correct view, waits for focus events, handles editor replacement, and consumes expired requests. Deferred autofocus is gated by request validity. Monaco and editor-content paths now forward and consume view-state identifiers. Tests cover focus timing, competing views, editor replacement, cleanup, and expiration. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
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 |
When opening a file to focus it, tag the pending request with the pane's viewStateId. This prevents split siblings from claiming each other's requests and stops later remounts from stealing focus. Both Monaco and rich-markdown editors now retire requests on mount.
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 9f0a92bd-f060-4237-83ad-70323dbeee43
📒 Files selected for processing (8)
src/renderer/src/components/editor/EditorContent.monaco-lifecycle.test.tsxsrc/renderer/src/components/editor/EditorContent.tsxsrc/renderer/src/components/editor/MonacoEditor.tsxsrc/renderer/src/components/editor/pending-editor-focus-request.test.tssrc/renderer/src/components/editor/pending-editor-focus-request.tssrc/renderer/src/components/editor/rich-markdown-auto-focus.tssrc/renderer/src/components/editor/useRichMarkdownPendingFocus.tssrc/renderer/src/store/slices/editor.test.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- src/renderer/src/store/slices/editor.test.ts
- src/renderer/src/components/editor/rich-markdown-auto-focus.ts
- src/renderer/src/components/editor/useRichMarkdownPendingFocus.ts
|
|
||
| // Why: every mount path above focuses, so an explicit open handoff is already satisfied here. | ||
| // Retiring it stops a later rich-mode remount of this same pane from stealing focus back. | ||
| const focusRequest = useAppStore.getState().pendingEditorFocusRequest | ||
| if ( | ||
| focusRequest && | ||
| matchesPendingEditorFocusRequest(focusRequest, { fileId, worktreeId, viewStateId }) | ||
| ) { | ||
| useAppStore.getState().consumeEditorFocusRequest(focusRequest.token) | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "Locate file and relevant symbols"
fd -a 'MonacoEditor.tsx' . || true
echo "Outline around relevant file"
file="$(fd 'MonacoEditor.tsx' . | head -n 1)"
if [ -n "${file:-}" ]; then
echo "FILE=$file"
wc -l "$file"
ast-grep outline "$file" --match '*focus*' --view expanded || true
echo "Relevant lines 480-600"
sed -n '480,600p' "$file" | nl -ba -v480
echo "Search focus request helpers/usages"
rg -n "pendingEditorFocusRequest|consumeEditorFocusRequest|matchesPendingEditorFocusRequest|requestAnimationFrame|hasTextFocus|onDidChangeFocus" "$file" .
fiRepository: stablyai/orca
Length of output: 617
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "Inspect imports and store type shape from source without running repo"
file="$(fd 'MonacoEditor.tsx' . | head -n 1)"
if [ -n "${file:-}" ]; then
sed -n '1,80p' "$file" | nl -ba
fi
echo "Find definitions of focus request terms across repo"
rg -n "pendingEditorFocusRequest|consumeEditorFocusRequest|matchesPendingEditorFocusRequest|type .*FocusRequest|interface .*FocusRequest" .Repository: stablyai/orca
Length of output: 261
🏁 Script executed:
#!/bin/bash
set -euo pipefail
file="./src/renderer/src/components/editor/MonacoEditor.tsx"
echo "FILE=${file}"
sed -n '520,590p' "$file"
printf '\n--- definitions/usages ---\n'
rg -n "pendingEditorFocusRequest|consumeEditorFocusRequest|matchesPendingEditorFocusRequest|requestAnimationFrame|hasTextFocus|onDidChangeFocus|autoSave" "$file"
printf '\n--- app store focus declarations ---\n'
rg -n "pendingEditorFocusRequest|consumeEditorFocusRequest|matchesPendingEditorFocusRequest|PendingEditorFocusRequest|EditorFocusRequest" .Repository: stablyai/orca
Length of output: 13147
Consume the pending focus request only after Monaco actually receives focus.
Lines 553-560 may call editorInstance.focus() from a delayed requestAnimationFrame, but the consume block runs before that RAF callback and without checking focus state. If the RAF is delayed, the editor is unmounted/disposed, or focus is rejected/stolen, the request is retired even though this mount never received focus, preventing a later valid retry. Apply the consumption callback from a focus listener and dispose it through the editor cleanup.
[low_effort_and_c_high_reward]
* fix(editor): preserve Markdown focus handoffs * fix(editor): scope focus requests to panes via viewStateId When opening a file to focus it, tag the pending request with the pane's viewStateId. This prevents split siblings from claiming each other's requests and stops later remounts from stealing focus. Both Monaco and rich-markdown editors now retire requests on mount.
Summary
Explorer-opened rich Markdown editors now claim explicit focus handoffs synchronously, so Cmd/Ctrl+F works without a document click even when Tiptap recreates the editor during mount.
Focus requests are consumed only after focus lands, scoped to the intended split-pane view, retried across destroyed editor instances, and expired after 30 seconds so stale requests cannot steal focus later.
Screenshots
No visual change.
Testing
pnpm lintpnpm typecheckpnpm testpnpm buildValidated with:
npx tsc --noEmit -p config/tsconfig.node.json --composite falsenpx tsc --noEmit -p config/tsconfig.web.json --composite falsenpx oxfmt --check -c .oxfmtrc.json <changed files>npx oxlint <changed files>npx vitest run --config config/vitest.config.ts src/renderer/src/components/editor --reporter=dot— 144 files, 959 tests passednpx electron-vite build --mode e2emarkdown-explorer-find-focus.spec.ts— 1 passedfile-open.spec.ts,markdown-prose-reflow.spec.ts, andrich-markdown-link-bubble-stacking.spec.ts— 9 passedAI Review Report
The review independently confirmed that the explicit focus was deferred through both Orca and Tiptap animation frames, could be cancelled during editor recreation, and was consumed before focus landed.
It flagged two additional lifecycle risks: stale requests surviving delayed mounts and multiple split panes competing for one request. The implementation now scopes requests to the target view-state ID, revalidates and cancels deferred focus at expiry, retains requests across destroyed editor instances, and consumes them only after focus is observed. Unit coverage was added for synchronous DOM focus, ordinary mounts, delayed consumption, destroyed-editor replacement, split-pane isolation, expiry retirement, and suspended deferred focus.
Cross-platform review covered macOS, Linux, and Windows. The change uses DOM focus behavior shared by all three platforms and does not alter shortcut detection or labels, paths, shell behavior, native modules, or Electron platform branches. Cmd/Ctrl handling remains in the existing platform-aware shortcut path.
Security Audit
No new external input handling, command execution, filesystem path handling, authentication, secrets, dependencies, IPC, or network behavior was introduced. The change is limited to renderer focus state and in-memory request metadata. No follow-up security work is needed.
Notes
The targeted and regression E2Es pass locally on macOS, but that cannot prove the Linux timing fix; Linux scheduled CI remains the authoritative validation.
An initial local E2E attempt used an incomplete concurrent build and failed because
window.__storewas absent. After a standalone E2E build completed, the target and all listed regression E2Es passed; this was a stale-build harness failure, not a product failure.