Repository navigation
Writing flow: Fix paste after drag-selecting text past a table cell's edge - #87090
NoumaanAhamed wants to merge 2 commits into
Conversation
…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.
🤖 PR meta 🤖👋 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. 🎉 PropsIf 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. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the 🏷️ LabelsThis pull request needs exactly one label indicating its type, and has 0.
Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you. |
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).useDragSelectiononly 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
mouseuphandler ofuseDragSelection, when there's no multi-block selection:Selections that really extend into another cell's text, or into another block, behave as before.
Testing Instructions
Hello worldin the first cell. Leave the other cells empty.Just.Hello worldfrom right to left, releasing the mouse past the left edge of the cell.Hello worldis replaced withJust.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.