Repository navigation
Conversation
…locks reach viewport edge Fixes WordPress#82839. Follow-up to WordPress#80708. In PR WordPress#80708, an early exit was added to `isEdge` in `@wordpress/dom` to prevent repeated page scrolls when navigating inside blocks taller than the viewport (WordPress#73801). However, the early exit assumed that whenever an element's edge point was outside the viewport while the selection was inside, they were at least a viewport boundary apart. In practice, for standard paragraph or heading blocks sitting near the bottom (or top) of the viewport, the block's text line is visible inside the viewport while its bottom padding/margin extends slightly beyond the viewport boundary. The distance between the caret line and the container edge is only a few pixels. The early exit mistakenly evaluated to true, reporting that the selection was not at the edge. Consequently, `useArrowNav` refused to transfer focus to the next block, and the browser's native caret handler had no subsequent lines to move to, causing the caret to freeze and auto-scrolling to halt. This commit resolves the regression by: 1. Ensuring the early exit only triggers when the container along that axis is actually larger than the viewport and the distance between the caret and the edge is substantial. 2. Re-evaluating the container's bounding rectangle inside the `scrollIfNoRange` callback so that if a container is scrolled into view, hit-testing probes the new coordinates. 3. Re-measuring the selection rectangle after `scrollIfNoRange` so comparisons against the test rectangle remain in sync. 4. Adding dedicated browser unit tests covering paragraph edge navigation near viewport boundaries as well as tall-block caret movement.
🤖 PR meta 🤖👋 Welcome👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @robelsust! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. 🎉 PropsUnlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @kurikimuchi. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Updated as activity occurs, without notifying anyone named here. Add the 🏷️ LabelsThis pull request needs exactly one label indicating its type, and has 0.
Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you. |
|
What?
Fixes #82839. Follow-up to #80708.
Fixes an issue where navigating downwards with the Down Arrow key (
ArrowDown) froze and ceased auto-scrolling when reaching a paragraph near the bottom boundary of the viewport.Why?
PR #80708 addressed #73801 (preventing repeated viewport scrolling inside blocks taller than the viewport) by adding an early exit in
isEdgewhen the test point was outside the viewport while the selection was inside.However, for standard paragraphs (e.g. 24px tall) sitting near the bottom of the viewport, the caret line is inside the viewport (
rangeRect.bottom <= innerHeight) while the container's bottom padding/line-height extends slightly below the boundary (y > innerHeight). The distance between the caret line and the edge is only a few pixels, butisFarFromVerticalEdgeprematurely returnedtrue. As a result,isEdgereturnedfalse,useArrowNavrefused to transfer focus to the next block, and navigation froze.How?
isEdgeto containers that actually exceed the viewport dimensions (containerRect.height > defaultView.innerHeight/containerRect.width > defaultView.innerWidth) where the selection is far from the probed edge (> innerHeight / 2). Containers that fit within the viewport can hit-test normally (scrolling a few pixels into view as needed) to traverse blocks.container.getBoundingClientRect()inside thescrollIfNoRangeprobe callback so that post-scroll coordinates are probed accurately.scrollIfNoRangeso differences againsttestRectare evaluated in the same frame of reference.Testing Instructions
scrollTop = 0).ArrowDown: verify navigation smoothly traverses from Paragraph 1 to the bottom without getting stuck.ArrowDown/ArrowUp: verify caret moves line-by-line without repetitive viewport scroll jumps (regression test for Unintended scrolling when editing inside tall blocks (long paragraphs, long quotes, or tall table cells) — caret moves but editor scrolls unpredictably #73801).npm run test:unit:vitest -- packages/dom/src/dom/test/is-edge.browser.test.js.