Repository navigation
Keep rich Markdown in place when focus returns from Find - #36781
Conversation
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes.
|
Review loop statusProblem. 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.
Verified.
Not verified.
Main breakage, not this PR. The four "SSH Windows hosts" jobs fail because that workflow's sparse checkout omits Note for #35764: both PRs add For Brennan's reviewHeading-link jump, then Toggle replace → Shift+Tab → editor: holds the stopping point (macOS, Review-note route back to the editor: holds the settled position: Where judgment matters:
Since review: main merge |
…6-md-find-viewport
) * 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
) * 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
) * 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
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:
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.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:
Validation:
4e6975f26a730164dbe6d52f036165894e547a50. The four SSH Windows host jobs fail on main's sparse-checkout breakage (they can't loadcloud/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.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.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.799948a2b14ec5c14997e2a34600746b744570dc(same app code as the head except the listener scoping in4e6975f26a7): 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.