Skip to content

Writing flow: fix shift+click selection between list items in Safari - #80663

Open
ellatrix wants to merge 1 commit into
trunkfrom
fix/safari-list-item-shift-click
Open

ellatrix wants to merge 1 commit into
trunkfrom
fix/safari-list-item-shift-click

Conversation

@ellatrix

Copy link
Copy Markdown
Member

What?

Fixes #80661. In Safari, shift+clicking from one list item to another extends the text selection again instead of just moving the caret.

Why?

Safari's mousedown default action focuses the nearest click-focusable element on the click path, and once it focuses something it treats the click as caret placement, ignoring Shift and discarding the selection being extended. #80651 removed the tabIndex from rich text elements, which fixed blocks whose wrapper is the rich text element (paragraphs, headings). A list item's wrapper (the li) is a separate element and keeps tabindex="0", so Safari still captures focus there. This is pre-existing behavior, not a regression.

How?

On a cross-block shift+mousedown, remove the tabindex from non-editable elements along the clicked path and restore it when the press ends (mouseup, or dragend when a native drag starts mid-press). Restoring earlier does not work: a microtask runs before the mousedown default action, so Safari would still see the tabindex when it captures focus (verified in real Safari). React re-renders do not resurrect the attribute mid-gesture because the rendered value is unchanged, so nothing rewrites it until the restore.

Testing Instructions

  1. In Safari, add a list with two items containing some text.
  2. Click in the middle of the first item's text, then shift+click in the middle of the second item's text.
  3. The selection extends between the two points. Before, the caret just moved to the second item.

Playwright's engines do not reproduce Safari's focus-capture behavior (the existing list item e2e test passes either way), so the fix is verified against real Safari via safaridriver, alongside the existing shift+click e2e suite in all three engines.

Use of AI Tools

Written with Claude Code, reviewed and tested by me.

…t+click

Safari's mousedown default action focuses the nearest click-focusable
element on the click path and then treats the click as caret placement,
ignoring Shift and discarding the selection being extended. Rich text
elements render without their tabIndex for this reason, but blocks
whose wrapper is a separate element from their rich text (a list item)
keep it on the wrapper, so a shift+click between list items never
extended in Safari. Remove the tabIndex on mousedown and restore it
when the press ends.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GQNdFF1FUU9JXfNGZev2na
@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

Copy link
Copy Markdown

Size Change: +132 B (0%)

Total Size: 7.75 MB

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

compressed-size-action

@github-actions

Copy link
Copy Markdown

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

@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>
Co-authored-by: noruzzamans <noruzzaman@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
Member

Tested! Confirms the fix works as expected. Shift+click between two list items now correctly extends the text selection in real Safari on macOS, instead of just moving the caret.

Environment: macOS, Safari (real browser, not Playwright's WebKit)

Screen.Recording.2026-07-24.at.12.53.12.PM.mov

@ellatrix ellatrix mentioned this pull request Aug 11, 2026
33 of 71 tasks

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.

Safari: shift+click from one list item to another does not extend the selection

2 participants