Skip to content

Writing flow: grow keyboard selections block by block over blocks without text - #80701

Open
ellatrix wants to merge 1 commit into
trunkfrom
fix/shift-arrow-skipped-blocks
Open

ellatrix wants to merge 1 commit into
trunkfrom
fix/shift-arrow-skipped-blocks

Conversation

@ellatrix

@ellatrix ellatrix commented Jul 24, 2026 •

Copy link
Copy Markdown
Member

What?

Fixes #53674. Extending a selection with shift+arrow into a block that does not support splitting (a spacer, a separator, a verse) selects that block as a block, instead of overshooting into the block beyond it. The selection grows and shrinks block by block.

Why?

A shift+arrow press moves the native focus to the nearest text position. A spacer has none, so the browser lands in the paragraph beyond it, and the observer faithfully recorded a three-block selection where two were expected. More generally, a partial selection has no value within a block that cannot split or merge: deleting such a selection removes the block whole anyway.

How?

In use-arrow-nav, at keydown: when the selection focus is at its block's edge in the key's direction and the adjacent block does not support splitting, select up to that block as a block and prevent the browser from acting. The store updates synchronously, so a fast next press cannot race it, and no overshot native selection ever exists. Mid-block presses and adjacent blocks that support splitting are left entirely to the browser, including its column memory. Further presses grow or shrink the block selection one block at a time (#63259 machinery).

The trade-off: the keyboard no longer produces a partial text selection ending inside a non-splitting block. Partial selections with a block in between remain possible when the blocks support splitting, and via mouse selection; the copy and cut tests for that case use a paragraph in the middle.

Testing Instructions

  1. Insert a paragraph, a spacer, and a paragraph. Put the caret in the middle of the first paragraph.
  2. Press Shift+ArrowDown: the first paragraph and the spacer are selected (previously all three blocks).
  3. Press Shift+ArrowDown again: all three blocks are selected. Shift+ArrowUp shrinks back to two.
  4. Replace the spacer with a verse: Shift+ArrowDown from the paragraph selects the paragraph and the whole verse.

Covered by e2e tests asserting each step in all three engines; they fail on trunk.

Use of AI Tools

Written with Claude Code, reviewed and tested by me.

@ellatrix ellatrix added [Type] Bug An existing feature does not function as intended [Feature] Writing Flow Block selection, navigation, splitting, merging, deletion... labels Jul 24, 2026
@github-actions github-actions Bot added the [Package] Block editor /packages/block-editor label Jul 24, 2026
@github-actions

github-actions Bot commented Jul 24, 2026 •

Copy link
Copy Markdown

Size Change: +122 B (0%)

Total Size: 7.72 MB

📦 View Changed
Filename Size Change
build/scripts/block-editor/index.min.js 460 kB +122 B (+0.03%)

compressed-size-action

@github-actions

github-actions Bot commented Jul 24, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ellatrix <ellatrix@git.wordpress.org>
Co-authored-by: noruzzamans <noruzzaman@git.wordpress.org>
Co-authored-by: annezazu <annezazu@git.wordpress.org>
Co-authored-by: bangank36 <bangank36@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: jasmussen <joen@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@noruzzamans

Copy link
Copy Markdown
Contributor

Tested! Confirms the fix works as expected. With a paragraph, spacer, and paragraph, Shift+ArrowDown first selects the paragraph and spacer, a second press selects all three, and Shift+ArrowUp shrinks back to two.

One observation: pressing Shift+ArrowUp again from two selected blocks deselects both back to a caret. This wasn't explicitly covered in the testing instructions, so not sure if it's intended, flagging in case it's useful.

Screen.Recording.2026-07-25.at.10.43.47.PM.mov

@ellatrix ellatrix mentioned this pull request Aug 11, 2026
27 of 81 tasks
…hout text

Squashed rebase of fix/shift-arrow-skipped-blocks onto current trunk.
@ellatrix
ellatrix force-pushed the fix/shift-arrow-skipped-blocks branch from fd4f6a4 to 1c78076 Compare August 13, 2026 00:42
@github-actions

Copy link
Copy Markdown

Flaky tests detected in 1c78076.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/31655312559
📝 Reported tests:

Navigates the items list via UP/DOWN arrow keys in /test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeFocused() failed

Locator:  getByLabel('Page Two')
Expected: focused
Received: inactive
Timeout:  5000ms

Call log:
  - Expect "toBeFocused" with timeout 5000ms
  - waiting for getByLabel('Page Two')
    14 × locator resolved to <button type="button" tabindex="-1" aria-pressed="false" id="view-list-0-251-item-wrapper" class="dataviews-view-list__item" aria-labelledby="view-list-0-251-label" aria-describedby="view-list-0-251-description"></button>
       - unexpected value "inactive"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js:112:49

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Writing Flow Block selection, navigation, splitting, merging, deletion... [Package] Block editor /packages/block-editor [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Writing Flow: Shift + down-arrow key to select across spacer block selects one too many blocks

2 participants