Skip to content

Writing flow: fix Down Arrow auto-scrolling navigation when blocks reach viewport edge - #84800

Closed
robelsust wants to merge 1 commit into
WordPress:trunkfrom
robelsust:fix/82839-writing-flow-arrow-down-autoscroll
Closed

robelsust wants to merge 1 commit into
WordPress:trunkfrom
robelsust:fix/82839-writing-flow-arrow-down-autoscroll

Conversation

@robelsust

Copy link
Copy Markdown
Contributor

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 isEdge when 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, but isFarFromVerticalEdge prematurely returned true. As a result, isEdge returned false, useArrowNav refused to transfer focus to the next block, and navigation froze.

How?

  1. Container Dimension & Distance Guard: Restrict the early-exit check in isEdge to 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.
  2. Dynamic Coordinate Calculation: Recompute container.getBoundingClientRect() inside the scrollIfNoRange probe callback so that post-scroll coordinates are probed accurately.
  3. Synchronized Post-Scroll Measurement: Re-measure the selection rectangle after scrollIfNoRange so differences against testRect are evaluated in the same frame of reference.

Testing Instructions

  1. In the Block Editor, insert 15–20 Paragraph blocks.
  2. Focus the first Paragraph block (with post title visible at scrollTop = 0).
  3. Press and hold ArrowDown: verify navigation smoothly traverses from Paragraph 1 to the bottom without getting stuck.
  4. Insert a Code block with 70+ lines, focus the middle line, and press 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).
  5. Run unit tests: npm run test:unit:vitest -- packages/dom/src/dom/test/is-edge.browser.test.js.

…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.
@robelsust
robelsust requested a review from ellatrix as a code owner October 15, 2026 05:24
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground

👋 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.

🎉 Props

Unlinked Accounts

The 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.

Unlinked contributors: kurikimuchi.

Co-authored-by: robelsust <therssoftware@git.wordpress.org>
Co-authored-by: hbhalodia <hbhalodia@git.wordpress.org>
Co-authored-by: Mayank-Tripathi32 <mayanktripathi32@git.wordpress.org>

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 props-bot label to refresh.

🏷️ Labels

This pull request needs exactly one label indicating its type, and has 0.

  • Required: any label starting with [Type].
  • Found: none.

Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you.

@hbhalodia

Copy link
Copy Markdown
Contributor

@hbhalodia hbhalodia closed this Oct 23, 2026
@robelsust
robelsust deleted the fix/82839-writing-flow-arrow-down-autoscroll branch October 23, 2026 05:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Package] DOM /packages/dom

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Writing Flow regression in 7.1] Down arrow key navigation fails to auto-scroll viewport when post title is visible

2 participants