Repository navigation
Fix Markdown Find editing without moving the caret or viewport - #25144
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (7)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughThe editor now hands focus back to editable content after eligible clicks when Find or Replace has focus. Search highlighting runs through a dedicated hook, which distinguishes navigation requests from ordinary match refreshes. Unit and end-to-end tests cover focus handoff, caret and selection behavior, scrolling, and editing while Find remains open. Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to The changed Markdown Find interactions are covered by focused editing and pointer tests, with no identified issue requiring a fix before merge. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 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 |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — the fix for #22693 (rich-Markdown Find no longer jumps the caret/viewport when editing after a search highlight refresh), plus its unit and Electron e2e coverage.
- Highlight refresh is now non-navigating — the effect extracted to
useRichMarkdownSearchHighlights.tsonly setsTextSelection+ scrolls whennavigationRequested || (searchChanged && !editor.isFocused), while still dispatching the decoration meta every time so highlights update. This is the core fix. - Explicit navigation still moves —
navigationRequestis bumped byreplaceCurrentMatch,replaceAllMatches, andmoveToMatch, so Next/Previous and replacement navigate even with the editor focused. - Focus handoff on document click —
focusRichMarkdownEditorFromSearch(wired into the scroll container'sonMouseDown) returns focus from the Find/Replace widget to the editor DOM withpreventScroll: true, only for primary, uncanceled presses on editable content in the same editor shell, skipping embedded controls and other editors. - Regression coverage — 4 editing unit tests assert caret/selection/scroll preservation and delayed-query behavior; 8 focus-helper unit tests; 4 Electron click/drag e2e cases.
I verified the focused unit tests (34) and the full src/renderer/src/components/editor suite (2040 tests) pass, pnpm tc:web and pnpm run check:code-quality:changed are clean, and the new editing tests genuinely fail under the old always-navigate behavior (3 of 4 fail), so they pin the regression rather than merely passing.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

ELI5
Keep Find open in Markdown and type or select exactly where you clicked, without jumping to another match or changing text elsewhere.
What Changed
Before, refreshing search highlights after a document edit also selected and scrolled to a match. Clicking another paragraph and typing
xyleftxthere but replaced a match elsewhere withy.Highlight refreshes now preserve the caret and viewport. Query/options changes navigate only while this editor's search controls have focus; Next/Previous and Replace explicitly request navigation. Delayed searches cannot take the caret back after you leave Find. Match positions are tied to the document they were computed from, so an intervening edit cannot apply stale ranges.
Clicks from Find/Replace into editable content transfer focus immediately without scrolling. Ordinary click/drag lets the browser place the selection. Shift-click restores the remembered selection first; handled table selections regain keyboard focus. Embedded controls and noneditable content keep their existing behavior.
Replace advances beyond the inserted text even if it still contains the query. Replace All preserves the mapped caret. Navigation uses current matches during the query debounce, and disposed/replaced editors cannot receive old navigation requests.
Why
#23175 was reverted by #24500 because its unconditional delayed editor-focus command scrolled to the old caret before a click or drag placed the new selection. Separating highlight refresh from navigation fixes the underlying editing interruption. Limiting the focus handoff to leaving Find/Replace preserves native pointer behavior, while synchronizing the saved selection for Shift avoids selecting from the document start.
Linked Issue
Fixes #22693
Regression coverage for #23596; replaces the reverted approach in #23175 / #24500.
Visual Proof
Same hidden macOS renderer and interaction: search for
Needle, scroll to another paragraph, click, then typexy.Before, typing replaces a match elsewhere and the viewport jumps. After, both characters stay at the clicked paragraph, the viewport stays put, and Find remains open with both matches intact.
Shift-click after returning to Find
Remember a caret in the first lower paragraph, focus Find, then Shift-click in the second paragraph. The earlier handoff selected from the document start; the corrected handoff selects only the intended range and copies those two paragraphs.
Table drag selection after switching Source to Rich
Testing
All 2,058 editor unit tests pass (3 skipped), across 290 passing files. New regressions use actual editor instances to cover typing/undo, stale render-to-effect ranges, delayed query updates, replacement progression, Replace All caret preservation, editor disposal/swaps, and Shift/table focus handoff.
All 10 distinct interaction checks pass through real hidden Electron renderers over Playwright/CDP on macOS. They cover Find/Replace click/drag typing, Source → Rich tables, Shift selection and copy, double-click replacement, embedded task/details/code controls, matching queries finishing after document/control interaction, Next/Replace, and Escape/reopen. Pointer holds span animation frames; selection-only checks assert stable viewport and clean document. Copy tests use synthetic clipboard events and leave the system clipboard untouched. No native windows were revealed.
ORCA_BACKGROUND_LAUNCH=1 pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/editor ORCA_BACKGROUND_LAUNCH=1 pnpm test:e2e tests/e2e/markdown-find-editing.spec.ts tests/e2e/markdown-find-adversarial.spec.ts --workers=1 ORCA_BACKGROUND_LAUNCH=1 pnpm tc:web pnpm run check:code-quality:changed pnpm run check:max-lines-ratchetRenderer typecheck, changed-code quality/design-system gates, targeted oxlint, formatting, and max-lines ratchet pass. The current Electron bundle was rebuilt for the interaction checks. Full
typecheck:e2estill reports 217 existing errors in unrelated tests and missing cloud dependencies; neither Markdown spec has an error. Windows/Linux physical keyboards and actual SSH transport were not tested locally. CI covers the broader build, lint, and test requirements.Review
Adversarial review reproduced and fixed saved-anchor Shift selection, handled table focus, stale match ranges, delayed query focus ownership, replacement text retaining matches, shrinking match counts, and disposed/replaced editor failures. Final review checks focus boundaries, native pointer behavior, effect timing, cleanup, and platform assumptions.
Agent skill upstream boundary
Notes
Renderer-only behavior shared by local, folder, and SSH workspaces. No execution-host, file-path, shortcut, wire-format, provider, or mobile changes. Existing match caching and read-only replacement guards remain in use.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (local checks above; CI runs again on the updated commit)