Skip to content

Fix Markdown Find editing without moving the caret or viewport - #25144

Merged
nwparker merged 2 commits into
mainfrom
nwparker/md-focus-fix
Oct 4, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/md-focus-fix

Conversation

@nwparker

@nwparker nwparker commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1272 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1272
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​187 $\color{#cf222e}{\Huge{\mathbf{−}}}$​65 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​122

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 xy left x there but replaced a match elsewhere with y.

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 type xy.

Before After
Before: editing jumps to another search match After: both characters remain at the clicked paragraph

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.

Before After
Before: Shift-click includes earlier paragraphs After: Shift-click selects only the intended paragraphs
Table drag selection after switching Source to Rich

The intended table text stays selected and the tab remains clean

Testing

  • I manually tested these changes locally
  • Automated tests added/updated

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-ratchet

Renderer 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:e2e still 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

  • Not applicable; this change copies no upstream skill source or resources.

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

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (local checks above; CI runs again on the updated commit)

@coderabbitai

coderabbitai Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 27b8cc81-3e37-49a1-91a2-3c9e7400bb5b
📥 Commits

Reviewing files that changed from the base of the PR and between 1dc6157 and 6b99118.

📒 Files selected for processing (7)
  • src/renderer/src/components/editor/RichMarkdownEditorSurface.tsx
  • src/renderer/src/components/editor/rich-markdown-search-focus.test.ts
  • src/renderer/src/components/editor/rich-markdown-search-focus.ts
  • src/renderer/src/components/editor/useRichMarkdownSearch.editing.test.tsx
  • src/renderer/src/components/editor/useRichMarkdownSearch.ts
  • src/renderer/src/components/editor/useRichMarkdownSearchHighlights.ts
  • tests/e2e/markdown-find-editing.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

The 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 6b991

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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 7 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The only directly linked issue, #22693, is closed and supplies historical context only. No active directly linked targets remain, so no linked-issue coding requirements apply.
Out of Scope Changes check ✅ Passed The reported changes address the PR’s stated Find/editing behavior: preserve the caret and viewport during highlight refresh, hand focus back to editable Markdown content, and test those interactions.…
Title check ✅ Passed The title clearly summarizes the main change: Markdown Find editing now preserves the caret and viewport.
Description check ✅ Passed The description covers the required sections, explains the user impact and approach, links an issue, includes visual proof, and details tests and known limitations. The manual-testing checkbox is unch…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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.ts only sets TextSelection + scrolls when navigationRequested || (searchChanged && !editor.isFocused), while still dispatching the decoration meta every time so highlights update. This is the core fix.
  • Explicit navigation still moves — navigationRequest is bumped by replaceCurrentMatch, replaceAllMatches, and moveToMatch, so Next/Previous and replacement navigate even with the editor focused.
  • Focus handoff on document click — focusRichMarkdownEditorFromSearch (wired into the scroll container's onMouseDown) returns focus from the Find/Replace widget to the editor DOM with preventScroll: 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.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker merged commit 8267b57 into main Oct 4, 2026
34 of 36 checks passed
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.

[Bug]: Active Ctrl+F find widget steals focus from editor and typing activates find widget buttons

1 participant