Possible to select a range of text and have `Selection.toString()` return empty string ("") despite text being selected (breaks browser context menu options that depend on selection.toString() being sane)
Categories
(Core :: DOM: Serializers, defect, P2)
Tracking
()
People
(Reporter: 13hurdw, Unassigned)
References
()
Details
Attachments
(1 file)
|
288.58 KB,
image/png
|
Details |
Firefox 67.0.4
Ubuntu
To reproduce:
- https://www.naheed.pk/tapal-gulbahar-green-tea-90gm
- Select blue heading text "Tapal Gulbahar Green Tea 90gm", right-click
Expected:
"Search for" context menu option
Actual:
Search context menu option is missing from the selection
<span class="base" data-ui-id="page-title-wrapper" itemprop="name">Tapal Gulbahar Green Tea 90gm</span>
Comment 1•7 years ago
|
||
Works for me on 68 beta on macOS.
Can you try a clean profile / restart with add-ons disabled and see if it still happens? Maybe it depends on being logged in or on add-ons you have, or something else?
I can still reproduce this in 68.0b14 with no add-ons (Fedora)
Selecting the entire text, there is no search option. If you select part of it, there will be the search menu option.
Comment 3•7 years ago
|
||
OK, so I finally managed to reproduce, but the manner of selection really ends up mattering - I originally just triple clicked in the <span>, and that always works (selects the text and shows the context menu).
So specific STR (I can repro on 68 beta and 69 nightly):
- open https://www.naheed.pk/tapal-gulbahar-green-tea-90gm
- move mouse to the left of the "Tapal Gulbahar Green Tea 90gm" text, as far left as you can without getting a zoom ( (+) ) cursor
- drag-select from there to past the right end of the text
- access
getSelection().toString()
ER:
the full string
AR:
empty string
Now, the anchorNode of the selection is the <div> that contains the image of the tea on the left, and the anchorOffset is 1, while the anchor node has only 1 child, ie the selection is from inside the div but does not include any of the children.
The focusNode is the text node inside the <span> that contains the text we're interested in, and the focusOffset is 29, which is the length of the text in the span.
So I'd expect the text to be selected, and it's visually shown as selected, but toString() does not return it. However, just using the copy shortcut or copy item does work and copy the selected text to the clipboard.
:tylin, I see you've done some work on selection, any chance you can look into this? Thanks!
Updated•7 years ago
|
Comment 4•7 years ago
|
||
I believe getSelection().toString() calls into nsDocumentEncoder::SerializeSelection(). This is the area I'm not familar with.
Mirko, I see you've patch heavily for the document encoder. Maybe you have better idea than I do?
It's not directly helpful, but might help with further debugging: document.getSelection().getRangeAt(0).toString() returns
"
if (window.matchMedia(\"(max-width: 767px)\").matches) {
$scroll = document.getElementById('MagicToolboxSelectors3005');
if ($scroll && typeof $scroll != 'undefined') {
$attr = $scroll.getAttribute('data-options');
if ($attr !== null) {
$scroll.setAttribute('data-options', $attr.replace(/orientation *\\: *[a-zA-Z]{1,}/gm, 'orientation:horizontal'));
}
}
} Tapal Gulbahar Green Tea 90gm"
which is also undesired.
Moreover, the issue reproduces also if the string is not selected until the end (e.g. focusOffset = 23).
Moreover, when pasting the selected text, it starts with a line break (!), e.g.:
Tapal Gulbahar Green Te
I suspect one of the problems could be in nsDocumentEncoder. Taking into account there are multiple symptoms, I guess there could be multiple underlying problems. I'd need to have deeper look into the code to judge it better.
Updated•7 years ago
|
Updated•3 years ago
|
Description
•