Firefox includes trailing space when selecting text via click and drag
Categories
(Core :: DOM: Copy & Paste and Drag & Drop, defect, P2)
Tracking
()
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:
- 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/).
- 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.
- 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.
Comment 1•5 years ago
|
||
Bugbug thinks this bug should belong to this component, but please revert this change in case of error.
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:
- Minimize the browser window so that "siteMetadata example" are in one line.
- Select "|siteMetadata |example".
- Resize the window so that "example" starts a new line.
- Observe the space isn't visually highlighted anymore.
- Copy-Paste via Ctrl+c and Ctrl+v.
- "siteMetadata " including the trailing space is pasted.
Using the "trick" steps in c3, this allows to reproduce the problem.
Updated•5 years ago
|
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.
Updated•3 years ago
|
Updated•2 years ago
|
Description
•