Skip to content

Keep rich Markdown in place when focus returns from Find - #36781

Merged
brennanb2025 merged 13 commits into
mainfrom
brennanb2025/sta-13206-md-find-viewport
Nov 1, 2026
Merged

brennanb2025 merged 13 commits into
mainfrom
brennanb2025/sta-13206-md-find-viewport

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​414 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​414
Prod 12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​511 $\color{#cf222e}{\Huge{\mathbf{−}}}$​46 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​465

Problem

In the rich Markdown editor, going back to the document from Find or Replace could throw away your reading position. You'd be reading far down the document, open Find, then press Tab or Shift+Tab to get back to the text (or the Replace field closed while it had focus), and the document jumped to the top and then to wherever the cursor was. On Windows a recorded return went from about 1985 px down to 0 and then to 1551 px; main on macOS does the same (about 2025 → 0 → 1630). Two things cause it: the browser scrolls the editor's scroll area when focus comes back, and the editor engine then scrolls again to reveal the cursor. This also blocks the Find selection work tracked in #35764.

What changes for users

Going back from Find or Replace keeps the document where you were reading, whether you return with Tab/Shift+Tab, with Escape, or after the Replace field closes. If you deliberately jumped somewhere just before returning (a Find match, a heading link, a review note, including a jump to the very top), that newer position is the one kept.

The same rule now applies to other ways focus comes back to this editor: closing a dialog, the command palette or a menu, pressing Escape in the link bubble, or opening a file keeps the reading position instead of jumping to the cursor. The cursor itself is still restored, and the first keystroke still scrolls it into view.

A smooth jump (for example clicking a heading link) that is interrupted by focus moving into the editor stops where the browser stops it, and the document stays there. Returns that don't scroll (Escape, closing a dialog) let the jump finish. An old jump is never restarted later.

How it works

Each rich Markdown editor gets one small helper tied to that editor and its scroll area:

  • A plain focus() call on the editor element becomes a focus that doesn't scroll. Calls that pass their own focus options are left exactly as they are.
  • When focus is about to move into the editor by keyboard, the helper reads the scroll position at that moment and puts it back if the browser moved it. The saved value only lives until the focus arrives (at most until the next browser task), so it can't be replayed later.
  • Find, review-note, table-of-contents, heading-link and editor-requested scrolls report their actual result immediately, so a jump made just before the return wins, including a jump to the top.
  • A small patch to the editor engine labels its "reveal the cursor after focus" scroll, and this editor skips only that one. Other editors and ordinary "scroll to the cursor" requests are unchanged.
  • The helper is removed when the editor, the document, or its scroll area is replaced, and it removes everything it added.

Selections and editing behave exactly as before; nothing saves or rebuilds the cursor.

This lands on its own on main. #35764 adds a patch for the same engine version and will merge its patch with this one when it syncs.

tracked in STA-13206
tracked in #35764

Full path: this changes focus and scroll ordering and the editor helper's lifecycle. The plan was reviewed, checked, and settled by a design panel before implementation, then went through the review loop.

Reference differences:

  • Intended: read the live scroll position at the moment focus moves, and have deliberate scrolls report their result immediately, instead of remembering positions from scroll events. Remembered positions can put back an older position over a jump whose scroll event hasn't arrived yet, and can't tell a deliberate jump to the top from the browser's reset.
  • Intended: make a plain focus call on this editor element not scroll, because a plain focus call on the element bypasses the editor engine's own scroll protection; other editors and supplied focus options stay unchanged.
  • Intended: skip the editor engine's cursor reveal after focus for this editor, matching the common pattern (closing a dialog, palette or menu, link-bubble Escape and file open keep the reading position). A focus from the page body with no keyboard or programmatic focus call (for example an assistive-technology focus after the Replace field is removed) has no saved position and stays where the browser puts it; that route was not exercised.
  • Intended: keep the existing selection behavior; no saved cursor, range replay, or selection rebuilding.

Validation:

  • CI on the current head: unit tests, typecheck, static analysis and the changed end-to-end specs (on Linux, run 41258104494) pass on 4e6975f26a730164dbe6d52f036165894e547a50. The four SSH Windows host jobs fail on main's sparse-checkout breakage (they can't load cloud/apps/connector/tsconfig.json), which also fails other PRs and is fixed by ci(ssh-windows): include cloud in the sparse checkout #36715; this PR only triggers that workflow because it touches the dependency patch list.
  • Unit tests (rich-markdown-viewport.test.tsx, real editor): a Find jump to a position or to the top before the scroll event arrives, then a return, keeps that position; a smooth heading jump interrupted by focus keeps the stopping point and is never reissued; nested focus, a plain focus after the Replace field is removed, exact focus options, Tab from the page body, an editor-requested scroll, scroll-area wheel input, heading-link and review-note scrolls, and full cleanup when the helper is removed.
  • End-to-end (Electron, tests/e2e/markdown-find-editing.spec.ts): plain focus, Replace field removed, Shift+Tab, and Escape returns keep the position, and a deliberate jump to the top is kept.
  • macOS app check on 799948a2b14ec5c14997e2a34600746b744570dc (same app code as the head except the listener scoping in 4e6975f26a7): after a heading-link jump, Toggle replace → Shift+Tab → editor stopped at 2533 px and held for 4.9 s, with no reset to the top and no restart toward the heading; the review-note route settled at 2403.5 px and held through five keyboard hops back to the editor and 7.2 s more. Cursor and document content were unchanged. Earlier macOS runs on previous heads passed the plain, Replace-removed, Shift+Tab, Escape, jump-to-top, newer-Find and review-note returns.
  • Not exercised: Windows on the final head (the original bug was recorded on Windows and main reproduces on macOS), assistive-technology focus, and a direct page-body-to-editor keyboard hop (not reachable in the measured layout).

@brennanb2025
brennanb2025 marked this pull request as ready for review November 1, 2026 00:35
@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Files ignored due to path filters: 1
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7e7d6c1a-40e5-4163-a269-a18653e402a2
Commits

Reviewing files that changed from the base of the PR and between 4e6975f and 87722ca.

Files ignored due to path filters: 1
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 58225641-a1fd-4c53-ab46-c72572871df3
Commits

Reviewing files that changed from the base of the PR and between 9527509 and 4e6975f.

Files selected for processing: 3
  • src/renderer/src/components/editor/rich-markdown-viewport.test.tsx
  • src/renderer/src/components/editor/rich-markdown-viewport.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; 7 remain after this review.

Walkthrough

The editor now binds a viewport to its root and scroll container. Focus handoffs can restore the container’s saved scroll position, and editor scrolling uses viewport-aware callbacks. The ProseMirror patch passes a focus reason to the selection scroll handler. Unit and end-to-end tests cover viewport ownership, scrolling, cleanup, and Find focus return paths.

Merge Risk: Minimal · previous review 4e697

No actionable merge-blocking issue was established in the viewport changes.

Pre-merge checks: Passed 3 · Failed 1 · Inconclusive 1

Failed Failed checks: 1 warning · 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check Inconclusive The description is thorough and mostly complete. It has a clear Problem section, a user-facing What changes for users section, a How it works section, and validation details. Testing is described in d… 1. Add an ELI5 section with a short, plain-language explanation. 2. Keep the 'What Changed' heading as its own section and summarize the before and after there. 3. Link an actual issue with 'Fixes #'. The description cites STA-13206…
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: preserving the rich Markdown viewport when focus returns from Find.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 7 functions across 11 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Full details: Description check

Explanation

The description is thorough and mostly complete. It has a clear Problem section, a user-facing What changes for users section, a How it works section, and validation details. Testing is described in depth across unit, end-to-end, and macOS runs. It covers the template's key information, including the mechanism, why it was chosen over alternatives, and the cross-platform gaps. Gaps against the template: the ELI5 section is missing, and the 'What Changed' heading is not used as a labeled section (its content sits under 'What changes for users' and 'How it works'). The Linked Issue section has no 'Fixes #' issue, and the author lists 'tracked in STA-13206' and 'tracked in #35764', which are references, not closing links. The Visual Proof section is missing; the author describes macOS and Windows runs in text but attaches no before/after screenshots or video, and the template requires them for UI behavior changes. The AI Disclosure section is blank. The Agent skill upstream boundary checkbox is absent. The Checklist items are not ticked, and the Testing checkboxes are not marked. The description also has a long PR-LoC table that the template does not need. Because the core content is present and only non-critical sections are missing, but the required visual proof and linked issue are absent, the check is inconclusive rather than a clear pass.

Resolution

  1. Add an ELI5 section with a short, plain-language explanation. 2. Keep the 'What Changed' heading as its own section and summarize the before and after there. 3. Link an actual issue with 'Fixes #<number>'. The description cites STA-13206 and #35764 only as tracking references, and the template says outside contributors need a real issue link. 4. Add a Visual Proof section with before and after screenshots or a video of the scroll position on return from Find. If that is not possible, write N/A and give the reason. The author's text-only macOS and Windows results do not replace this. 5. Fill in the AI Disclosure section, or state that it does not apply. 6. Complete the Agent skill upstream boundary checkbox. 7. Tick the Testing checkboxes that apply, and state the platforms actually tested (macOS and Linux CI; Windows not run on the final head). 8. Review the Checklist and mark the items that are complete, including lint, typecheck, test, and build status. The PR's objectives state that no standalone lint, typecheck, full suite, or build run was performed, so those items need either a run or a note that CI covers them.
Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
  • Autofix · 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

@brennanb2025

brennanb2025 commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Review loop status

Problem. In the rich Markdown editor, returning from Find or Replace to the document (Tab/Shift+Tab, Escape, or the Replace field closing) threw away the reading position. The document jumped to the top and then to the cursor (Windows about 1985 → 0 → 1551 px, macOS 2025 → 0 → 1630). The browser scrolls the editor's scroll area when focus comes back, then the editor engine scrolls again to reveal the cursor.

What users get. Going back from Find or Replace keeps the document where you were reading, and a deliberate jump made just before the return (Find match, heading link, review note, including the very top) wins. The same now holds when closing a dialog, the command palette or a menu, pressing Escape in the link bubble, or opening a file: the reading position stays and the cursor is restored without a scroll jump, matching the common pattern. A smooth jump interrupted by a focus that moves the viewport stops where the browser stops it and is never restarted.

Review. Full path, 3 rounds plus 2 CI repairs. Round 1 used three fresh reviewers (correctness, consumers and user-visible result, architecture challenger). No P0 or P1 was found.

  • Fixed: the PR description now labels the skipped cursor reveal and its wider effect as intended, and words the smooth-jump behavior accurately; tests now cover removing the focus wrapper, and the heading-link and review-note scroll call sites; per-editor app-wide wheel and touch listeners were moved onto the editor's own scroll area so their cost no longer grows with open editors; two test-only CI repairs (a mock type, and a documented exception for the 250 ms wait that proves nothing moves during the engine's 200 ms post-focus window).
  • Deferred:
    • The deliberate-scroll reporting layer is kept although no shipped scroll runs inside the one-task focus window today. The design panel's latest-position rule selected it, and nothing showed it failing.
    • Some input listeners only guard a narrow edge case and are kept.
    • Two cases behave the same as main: a Find jump inside a review card's two preparation frames is overridden by the card scroll, and removing the helper doesn't cancel a smooth jump already in flight on a reused scroll area.
  • Readiness checklist: nothing blocking.

Verified.

  • CI on 4e6975f26a730164dbe6d52f036165894e547a50: unit, typecheck, static analysis and the changed end-to-end specs pass (run).
  • macOS app check on 799948a2b14ec5c14997e2a34600746b744570dc: after a heading-link jump, Toggle replace → Shift+Tab → editor held at 2533 px with no reset or restart. The review-note route held at 2403.5 px through five keyboard hops. Earlier macOS runs passed the plain, Replace-removed, Shift+Tab, Escape, jump-to-top and newer-Find returns.
  • Commits since the app check: 9527509b3b8 and ed8d6175c1a change tests only. 4e6975f26a7 moves the wheel and touch guard from the window to the editor's scroll area (focus-return flow), covered by a new unit assertion that fails without the guard and by the end-to-end specs above.

Not verified.

  • Windows on the final head (the original bug was recorded on Windows; main reproduces on macOS).
  • Assistive-technology focus: a focus from the page body with no keyboard or focus call has no saved position and stays where the browser puts it. It's labelled in the PR body, and no accessibility automation is allowed on our machines.
  • A direct page-body-to-editor keyboard hop (not reachable in the measured layout).

Main breakage, not this PR. The four "SSH Windows hosts" jobs fail because that workflow's sparse checkout omits cloud/ (TSCONFIG_ERROR … cloud/apps/connector/tsconfig.json); another PR fails the same way. #36715 fixes it. This PR triggers that workflow only because it adds an engine patch to the dependency list. It is ready once #36715 lands and those jobs re-run green.

Note for #35764: both PRs add config/patches/[email protected]; #35764 merges the hunks when it syncs.

For Brennan's review

Heading-link jump, then Toggle replace → Shift+Tab → editor: holds the stopping point (macOS, 799948a2b14ec5c14997e2a34600746b744570dc):
(screenshot removed: contained real product data)

Review-note route back to the editor: holds the settled position:
(screenshot removed: contained real product data)

Where judgment matters:

  1. rich-markdown-viewport.ts:51: the engine's post-focus cursor reveal is skipped for this editor on every focus, not only on returns that saved a position (behavior change beyond Find).
  2. rich-markdown-viewport.ts:170: the focus-return repair (endpoint matching, page-body Tab case).
  3. [email protected]:9: the engine patch that labels only the post-focus reveal.

Since review: main merge 87722ca3489 (clean, no conflicts) picks up #36715's Windows SSH CI fix; no PR code changed.

@brennanb2025
brennanb2025 merged commit 9eb9301 into main Nov 1, 2026
127 of 129 checks passed
@brennanb2025
brennanb2025 deleted the brennanb2025/sta-13206-md-find-viewport branch November 1, 2026 19:48
Nenzyz pushed a commit to Nenzyz/orca that referenced this pull request Nov 2, 2026
)

* Preserve rich Markdown viewport through bare focus returns

* Retire viewport ownership on editor remount

* Complete no-op navigation and body Tab coverage

* Keep patch metadata keys separate from dependency snapshots

* Retire the viewport before root detach callbacks

* Give the engine writer fixture its native selection

* Keep native focus navigation current in Markdown

* fix: leave smooth Markdown scrolling to native focus cancellation

* Cover focus wrapper removal and routed Markdown writers

* Type the viewport scroll spy and mark the focus-recovery wait as deliberate

* Scope Markdown viewport wheel and touch guards to the editor scroller
Nenzyz pushed a commit to Nenzyz/orca that referenced this pull request Nov 2, 2026
)

* Preserve rich Markdown viewport through bare focus returns

* Retire viewport ownership on editor remount

* Complete no-op navigation and body Tab coverage

* Keep patch metadata keys separate from dependency snapshots

* Retire the viewport before root detach callbacks

* Give the engine writer fixture its native selection

* Keep native focus navigation current in Markdown

* fix: leave smooth Markdown scrolling to native focus cancellation

* Cover focus wrapper removal and routed Markdown writers

* Type the viewport scroll spy and mark the focus-recovery wait as deliberate

* Scope Markdown viewport wheel and touch guards to the editor scroller
Nenzyz pushed a commit to Nenzyz/orca that referenced this pull request Nov 2, 2026
)

* Preserve rich Markdown viewport through bare focus returns

* Retire viewport ownership on editor remount

* Complete no-op navigation and body Tab coverage

* Keep patch metadata keys separate from dependency snapshots

* Retire the viewport before root detach callbacks

* Give the engine writer fixture its native selection

* Keep native focus navigation current in Markdown

* fix: leave smooth Markdown scrolling to native focus cancellation

* Cover focus wrapper removal and routed Markdown writers

* Type the viewport scroll spy and mark the focus-recovery wait as deliberate

* Scope Markdown viewport wheel and touch guards to the editor scroller
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