Skip to content

Writing flow: Fix paste after drag-selecting text past a table cell's edge - #87090

Open
NoumaanAhamed wants to merge 2 commits into
WordPress:trunkfrom
NoumaanAhamed:fix/86969-table-cell-drag-select-paste
Open

NoumaanAhamed wants to merge 2 commits into
WordPress:trunkfrom
NoumaanAhamed:fix/86969-table-cell-drag-select-paste

Conversation

@NoumaanAhamed

Copy link
Copy Markdown

What?

Closes #86969

Restores focus to the rich text element after a drag selection that ends just outside it, so copy/paste works after drag-selecting text in a table cell.

Why?

When drag-selecting text in a table cell and releasing the mouse past the cell's edge, or over an empty neighboring cell, the browser places a selection boundary outside the cell's rich text element (on the td, or inside the neighboring cell's empty rich text). useDragSelection only restored focus when the whole range was inside the anchor element, so focus was never restored. The table block was left fully selected, and pasting did nothing.

How?

In the mouseup handler of useDragSelection, when there's no multi-block selection:

  • Clamp the range's start and/or end to the anchor element if they fall outside it.
  • Apply the clamped range and focus the anchor element only if no text is lost by clamping. Whitespace is ignored when comparing, which also covers the placeholder (ZWNBSP) of empty rich text.

Selections that really extend into another cell's text, or into another block, behave as before.

Testing Instructions

  1. Insert a Table block (e.g. 2×2) and type Hello world in the first cell. Leave the other cells empty.
  2. Copy some text, e.g. Just.
  3. Drag-select Hello world from right to left, releasing the mouse past the left edge of the cell.
  4. Paste. Hello world is replaced with Just.
  5. Repeat, this time dragging from left to right and releasing the mouse in the empty cell to the right. Paste replaces the selected text.
  6. Regression checks:
    • Drag from the first cell into the text of a neighboring cell that has content. Behavior is unchanged from trunk.
    • Drag from a paragraph into the next block. The blocks are multi-selected as before.

Testing Instructions for Keyboard

Not applicable. This only affects mouse drag selection. Keyboard selection (Shift + Arrow keys) followed by Cmd/Ctrl + V is unchanged.

Screenshots or screencast

Use of AI Tools

AI tooling was used to assist with investigation and code. I reviewed, tested manually and take responsibility for the changes.

…utside it

When drag-selecting text in a table cell and releasing the mouse past the
cell's edge or in an empty neighboring cell, the selection boundary lands
outside the rich text element. Focus was then not restored, leaving the
whole table block selected, so pasting did nothing.

Clamp the range to the anchor element when doing so doesn't drop any
selected text.
@github-actions github-actions Bot added the [Package] Block editor /packages/block-editor label Nov 19, 2026
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground Preview in Storybook

👋 Welcome

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @NoumaanAhamed! In case you missed it, we'd love to have you join us in our Slack community.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

🎉 Props

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: NoumaanAhamed <mohamedahamed@git.wordpress.org>
Co-authored-by: umeshnevase <umeshnevase@git.wordpress.org>
Co-authored-by: talldan <talldanwp@git.wordpress.org>
Co-authored-by: dionysous <dionysous@git.wordpress.org>

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


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

🏷️ Labels

This pull request needs exactly one label indicating its type, and has 0.

  • Required: any label starting with [Type].
  • Found: none.

Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you.

@github-actions github-actions Bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Nov 19, 2026

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

First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Package] Block editor /packages/block-editor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Table Block: Cannot copy/paste when selecting cell text without clicking into cell first [UX]

1 participant