gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Selecting text to insert a link doesn't always link the entire text

Open room34 opened this issue 1 year ago • 9 comments

Description

I've observed this issue both on my own WordPress 6.8.2 sites, and also when posting in the WordPress support forums, which uses the Gutenberg interface. I'm using a Mac with Safari.

I've found that often, if not most of the time, when I select text to turn into a link, with my habit of selecting from the right-to-left, even though I've selected the full text I want to link, the inserted link omits the first few letters.

This also happens when I'm selecting text to delete and replace (i.e. selecting the old text and then clicking Command-V to insert text from my clipboard); a few letters of the first word will be left over.

The problem never seems to happen if I select from left-to-right, but since my cursor is usually coming in from the right, I typically select right-to-left.

Step-by-step reproduction instructions

  1. Edit a post. Enter some text.
  2. Select the text by double-clicking in the last word (to select the full word) and then dragging the cursor to the beginning of the text you wish to link.
  3. Insert the link. Some letters from the first word will (not always, but often/usually) be excluded from the link.

In some cases the selection also deselects part of the word, which may be due to my inaccurate cursor movement, but even when the full word is definitely in the selection, the link may omit part of the word.

Screenshots, screen recording, code snippet

https://github.com/user-attachments/assets/ebbd05a2-a4f2-4d6a-b0bb-ce07a8b51850

Environment info

WordPress 6.8.2 (not using the Gutenberg plugin). Theme is irrelevant as this happens on multiple sites and also in the wordpress.org forums. Mac OS Sequoia 15.5 with Safari 18.5.

Please confirm that you have searched existing issues in the repo.

  • [x] Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • [x] Yes

Please confirm which theme type you used for testing.

  • [ ] Block
  • [ ] Classic
  • [x] Hybrid (e.g. classic with theme.json)
  • [ ] Not sure

room34 avatar Aug 05 '25 23:08 room34

Reproduction Report

Description

This report validates whether the issue can be reproduced.

Environment

  • WordPress: 6.9-alpha-60272
  • PHP: 8.2.28
  • Server: Apache/2.4.62 (Debian)
  • Database: mysqli (Server: 11.4.7-MariaDB-ubu2404 / Client: mysqlnd 8.2.28)
  • Browser: Chrome 138.0.0.0
  • OS: macOS
  • Theme: Twenty Twenty-Five 1.2
  • MU Plugins:
    • Gutenberg Test Plugin, Disable Login Autofocus
    • Gutenberg Test Plugin, Disable Remote Patterns
    • Gutenberg Test Plugin, Enable Templates UI
    • Gutenberg Test Plugin, No-cache Headers
    • Gutenberg Test Plugin, Normalize Theme
    • server-timing.php
  • Plugins:
    • Gutenberg 21.3.0
    • Test Reports 1.2.0

Actual Results

  1. ❌ Error condition doesn't occur (can't reproduce).

Additional Notes

  • Followed the exact steps mentioned in the issue.

Supplemental Artifacts

https://github.com/user-attachments/assets/83501d99-31ba-4be2-8cdf-1d15d0aa6975

Adi-ty avatar Aug 06 '25 07:08 Adi-ty

@Adi-ty, this could be a browser-specific problem. It looks like you're testing with Chrome, and the initial report says Safari 18.5.

Mamaduka avatar Aug 06 '25 07:08 Mamaduka

@Mamaduka Thanks for pointing that out! I just tested it on Safari 18.5 as well, but I'm still unable to reproduce the issue on my end.

https://github.com/user-attachments/assets/b9684852-f795-46d8-85d8-650a25f8dff8

Adi-ty avatar Aug 06 '25 08:08 Adi-ty

I'm also having trouble reproducing the issue on Safari. @room34, please let us know if we're missing something from the reproduction steps.

Screencast

https://github.com/user-attachments/assets/41f27107-9e23-4f39-a436-252cfe4ad669

Mamaduka avatar Aug 06 '25 09:08 Mamaduka

@Mamaduka @Adi-ty I was able to reproduce the issue and found that it occurs when there are three or more words in a sentence being linked, and the first word has more than one character.

Environment

  • WordPress: 6.9-alpha-60609
  • PHP: 8.2.29
  • Server: Apache/2.4.62 (Debian)
  • Database: mysqli (Server: 11.8.2-MariaDB-ubu2404 / Client: mysqlnd 8.2.29)
  • Browser: Safari 18.6
  • OS: macOS
  • Theme: Twenty Twenty-Five 1.3
  • MU Plugins: None activated
  • Plugins:
    • Gutenberg 21.3.0
    • Test Reports 1.2.0

(This happens when you double-click on the last word and then drag to the first word to select the entire sentence.)

https://github.com/user-attachments/assets/23e5efb9-b76e-44f1-af87-822fd4a6d8e0

Additionally, while experimenting, I noticed that if there are only two words and the first word has only one character, then only the first word gets hyperlinked.

https://github.com/user-attachments/assets/7650622e-318e-4a2b-afc3-78e3ea6873b4

BugReportOnWeb avatar Aug 06 '25 10:08 BugReportOnWeb

Thanks for the Reproduction confirmation @BugReportOnWeb

Can you confirm the environment variables? (try to remember always not to forget to use the template as we do in the triaging sessions; it helps a lot for future reproducers.)

SirLouen avatar Aug 06 '25 13:08 SirLouen

Thanks, @BugReportOnWeb! That seems to be the exact case.

I've tested this behavior in Chrome/Firefox/Safari, and I can only reproduce it in Safari.

The drag selection seems to have different issues in FF. If I try selecting a whole paragraph from a partial selection, it doesn't work. The drag selection only works if I start at the end of a paragraph.

Screencast/ Firefox

https://github.com/user-attachments/assets/87c98cc7-7255-4368-b976-121cdbb12137

Mamaduka avatar Aug 06 '25 14:08 Mamaduka

Thanks for the reminder, @SirLouen! I'll make sure to include the template in the future. Regarding the environment variables, I'll update my original comment with those.

BugReportOnWeb avatar Aug 06 '25 17:08 BugReportOnWeb

I've retested this with the latest Safari (Version 26.1) and can no longer reproduce the bug. I'm going to close the issue.

Mamaduka avatar Dec 03 '25 13:12 Mamaduka