Skip to content

Writing flow: fix triple click extending the selection into the next block - #81022

Open
t-hamano wants to merge 7 commits into
trunkfrom
fix/triple-click-selection-overshoot
Open

Writing flow: fix triple click extending the selection into the next block#81022
t-hamano wants to merge 7 commits into
trunkfrom
fix/triple-click-selection-overshoot

Conversation

@t-hamano

@t-hamano t-hamano commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

What?

Follow up to #80126.

Triple clicking a paragraph sometimes starts a multi selection with the next block, or selects the parent block, instead of selecting the paragraph's text.

Why?

Triple clicking a paragraph should select that paragraph's text. Instead, when the block below it is a separator, group, quote, list or image, the editor starts a multi selection that also covers that block, so typing next replaces both blocks. When the paragraph is the last one inside a container, the selection reaches past the container and its parent block is selected as a whole.

How?

An editableRoot makes the writing flow wrapper the editing host, and Chromium then extends the triple click's selection past the paragraph. extractSelectionEndNode already pulls that overshoot back, but it recognises only one of the DOM positions the browser reports it at, so the blocks above are left uncorrected.

It now walks back from that boundary to the text node before it and ends the selection there, so the end maps to the clicked block no matter which DOM position the browser reported. The correction only applies when that text node is in the block the selection started in, so a triple click and drag into another block still makes a multi selection.

Whether the selection runs forward is now decided by comparing the range end with the focus, instead of by isSelectionForward, which compares node positions and so reports the focus as preceding the anchor when it is an ancestor of it — as it is for a separator, where the browser reports the boundary on the root container.

Testing Instructions

A paragraph followed by another block

  1. Add a paragraph with some text, and a Separator, List, Image or Group block below it.
  2. Triple click the paragraph text.
  3. Only that paragraph is selected.

The last paragraph in a container

  1. Add a Group with two paragraphs in it, and a Image block below the group, outside it.
  2. Triple click the second paragraph in the group.
  3. Only that paragraph is selected.

Screenshots or screencast

Before

triple-click-before.mp4

After

triple-click-after.mp4

Use of AI Tools

Authored with Claude Code (Opus 5) under my direction and review: the root cause investigation, the fix and the two e2e tests.

t-hamano and others added 2 commits July 31, 2026 21:59
…block

A triple click in a block with an editable root makes the browser extend
the forward selection past the block. `extractSelectionEndNode` only
compensated when the boundary was reported at an offset of 0 in a sibling
of the clicked block, so the end still resolved to another block when the
next block is a separator (the boundary is reported at the separator
itself) or a container such as a group (the boundary has no preceding
sibling), starting a multi selection.

Move the end back to the last text position before the boundary instead,
but only when it is in the block the selection starts in, so a triple
click and drag across blocks is left alone. Detect the forward selection
from the range end rather than with `isSelectionForward`, which compares
node positions and reports the focus as preceding the anchor when it is an
ancestor of it.

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added the [Package] Block editor /packages/block-editor label Jul 31, 2026
@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown

Size Change: +144 B (0%)

Total Size: 7.78 MB

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

compressed-size-action

@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended [Feature] Writing Flow Block selection, navigation, splitting, merging, deletion... Backport to WP 7.1 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta labels Jul 31, 2026
@t-hamano t-hamano self-assigned this Jul 31, 2026
t-hamano and others added 3 commits July 31, 2026 22:55
Co-Authored-By: Claude <noreply@anthropic.com>
The overshoot of a triple click can be reported inside the next block, on
an element that has no children — an element of an image placeholder, for
instance. The offset then equals the number of child nodes, so the end
node was returned before the correction could run and the block below was
pulled into a multi selection.

Resolve the end node in that branch as well, and skip the correction when
the end already maps to the block the selection starts in, so an end at
the end of a nested element within the block is left where it is.

Co-Authored-By: Claude <noreply@anthropic.com>
New entries go at the end of the section, so the list stays in the order
the changes landed.

Co-Authored-By: Claude <noreply@anthropic.com>
@t-hamano
t-hamano requested a review from ellatrix July 31, 2026 14:27
@t-hamano
t-hamano marked this pull request as ready for review July 31, 2026 14:27
@github-actions

github-actions Bot commented Jul 31, 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: t-hamano <wildworks@git.wordpress.org>
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.

@ellatrix

Copy link
Copy Markdown
Member

Thanks, looking into this

t-hamano and others added 2 commits August 1, 2026 11:10
The tests pressed ArrowUp to move the selection off the block inserted
after the paragraph, so its block toolbar would no longer overlap the
text that gets triple clicked. That does not work for a placeholder
block: focus lands on a form element inside the placeholder, which
useArrowNav skips, so the image block stayed selected and its toolbar
intercepted the click.

Dispatch the selection instead, which does not depend on where focus
happens to be after insertion.

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

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown

Flaky tests detected in a9846a8.
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/30832942740
📝 Reported issues:

@t-hamano

t-hamano commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Since editableRoot support is being removed, this PR no longer needs to be released in 7.1. See #81184

@t-hamano t-hamano removed the Backport to WP 7.1 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Aug 5, 2026
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

Status: 🔎 Needs Review

Development

Successfully merging this pull request may close these issues.

2 participants