Writing flow: fix triple click extending the selection into the next block - #81022
Writing flow: fix triple click extending the selection into the next block#81022t-hamano wants to merge 7 commits into
Conversation
…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>
|
Size Change: +144 B (0%) Total Size: 7.78 MB 📦 View Changed
|
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>
|
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 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. |
|
Thanks, looking into this |
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>
|
Flaky tests detected in a9846a8. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/30832942740
|
|
Since |
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
editableRootmakes the writing flow wrapper the editing host, and Chromium then extends the triple click's selection past the paragraph.extractSelectionEndNodealready 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
The last paragraph in a container
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.