Skip to content

Writing flow: synchronize cross-block selections before events that consume them#80152

Open
ellatrix wants to merge 1 commit into
trunkfrom
add/writing-flow-cross-block-selection-sync
Open

Writing flow: synchronize cross-block selections before events that consume them#80152
ellatrix wants to merge 1 commit into
trunkfrom
add/writing-flow-cross-block-selection-sync

Conversation

@ellatrix

Copy link
Copy Markdown
Member

What?

Update the store with a cross-block selection right before any event that acts on it: keydown, beforeinput, copy, cut and paste. The single-block counterpart landed in #80151; this covers selections that span blocks, which the selection observer owns.

Why?

The store receives cross-block selections from the asynchronous selectionchange event. When a consuming event arrives first, its handlers act on the previous selection: the clipboard handler copies or replaces the wrong blocks, and typing or pressing Enter over a fresh selection goes through writing flow reading a stale multi-selection.

How?

The observer's selectionchange handler is also called on capture of the five events when the native selection spans blocks. A snapshot of the last processed selection skips the work when the store is already up to date; without it, re-processing would re-dispatch multiSelect, which announces the selection to screen readers on every call.

Also, the single-block dispatch now skips selections the store already holds: the mouseup after a drag re-processed the selection that the last selectionchange event had already dispatched, re-rendering for nothing.

Extracted from #79105.

Written with the help of Claude Code.

🤖 Generated with Claude Code

…onsume them

The store receives a cross-block selection from the asynchronous
selectionchange event, so a consuming event that arrives first acts on
the previous selection: keyboard handling and the clipboard handler
read the store's multi-selection at keydown, beforeinput, copy, cut
and paste. Process the native selection on capture of those events
when it spans blocks; a snapshot of the last processed selection skips
the work when the store is already up to date. Selections within one
block are synchronized the same way by rich text itself.

Also skip dispatching a single-block selection the store already
holds: the mouseup after a drag re-processes the selection that the
last selectionchange event already dispatched.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions

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>

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

@github-actions github-actions Bot added the [Package] Block editor /packages/block-editor label Jul 13, 2026
@github-actions

Copy link
Copy Markdown

Size Change: +284 B (0%)

Total Size: 7.71 MB

📦 View Changed
Filename Size Change
build/scripts/block-editor/index.min.js 419 kB +284 B (+0.07%)

compressed-size-action

@github-actions

Copy link
Copy Markdown

Flaky tests detected in 8a472d3.
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/29218315074
📝 Reported issues:

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

Labels

[Package] Block editor /packages/block-editor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant