Open Bug 1625057 Opened 5 years ago Updated 9 months ago

Firefox includes trailing space when selecting text via click and drag

Categories

(Core :: DOM: Copy & Paste and Drag & Drop, defect, P2)

75 Branch
defect

Tracking

()

UNCONFIRMED

People

(Reporter: djpowers89, Unassigned)

References

Details

Attachments

(3 files)

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:75.0) Gecko/20100101 Firefox/75.0

Steps to reproduce:

  1. Identify a code element that occurs immediately before a line wrap (at full-width, look for "src/pages/sweet-pandas-eating-sweets.md" or "siteMetadata" in this example: https://www.gatsbyjs.org/tutorial/part-six/).
  2. Click and drag to select from the beginning of the text in the code element, and drag past the end of the word and code element.
  3. Copy the selection to the clipboard.

Actual results:

The text selection appears the same as if it was double-clicked to select, but when the result is pasted it contains a trailing space: "siteMetadata "

Expected results:

The text selection should not include a trailing space, as that is not visually indicated in the selection. Pasting the selection should result in "siteMetadata"

In Google Chrome, the text selection in this specific scenario begins to include the next line.

The root cause of the bug appears to be that clicking and dragging past the end of a (wrapped) line in a paragraph includes the space at the end. Google Chrome does not do this, which I believe results in a more streamlined experience. Regardless of your opinion of that behavior, the original scenario described should at the very least show a space in the selection if that is going to be part of the copied result.

Bugbug thinks this bug should belong to this component, but please revert this change in case of error.

Component: Untriaged → DOM: Editor
Product: Firefox → Core
Flags: needinfo?(mbrodesser)
See Also: → 1043118
Component: DOM: Editor → DOM: Selection
Flags: needinfo?(mbrodesser)

Reproducible on Ubuntu 18.04. document.getSelection().toString() already contains the trailing space.

Interestingly,

document.getSelection().focusNode.textContent
" example, source plugins can live-reload data.
"
document.getSelection().focusOffset
1

That is, the trailing space is part of the Selection (because focusNode.textContent contains a leading space character), but the visual presentation doesn't reflect that.

Chrome can be 'tricked' to the same wrong presentation:

  1. Minimize the browser window so that "siteMetadata example" are in one line.
  2. Select "|siteMetadata |example".
  3. Resize the window so that "example" starts a new line.
  4. Observe the space isn't visually highlighted anymore.
  5. Copy-Paste via Ctrl+c and Ctrl+v.
  6. "siteMetadata " including the trailing space is pasted.
Attached file smaller_example.html

Using the "trick" steps in c3, this allows to reproduce the problem.

Component: DOM: Selection → DOM: Editor
Priority: -- → P2
Attached file smaller_example2.html

Smaller example. The problem seems to occur for inline elements like <code> and <b>.

Using smaller_example2.html, the console shows that the Selection's focusNode is wrong:

Selection { anchorNode: #text, anchorOffset: 0, focusNode: #text, focusOffset: 4
document.getSelection().anchorNode.textContent
"asdf"
document.getSelection().focusNode.textContent
"
   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  

"

Edit: the focusOffset is wrong too (can be checked by changing asdf to asdfasdf; the focusOffset will stay 4).

It seems the focus node and offset are set wrongly, either because the input point to nsFrameSelection::HandleDrag is already wrong, or because GetContentOffsetsFromPoint does something wrongly.

As it seems related.

See Also: → 1623764
Assignee: nobody → mbrodesser
Assignee: mbrodesser → nobody
Severity: normal → S3
Component: DOM: Editor → DOM: Copy & Paste and Drag & Drop
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: