window.getElement has incorrect anchorNode if there is a unselectable element inside selection
Categories
(Core :: DOM: Selection, defect)
Tracking
()
People
(Reporter: ninadsinhaa, Unassigned)
References
(Regression)
Details
(Keywords: regression)
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/118.0
Steps to reproduce:
I created 3 span elements, with the middle one being unselectable using CSS attribute (user-select: none). When selecting text and fetching it through window.getSelection, anchorNode should be the first element, and focusNode should be the last element.
Relevant jsfiddle: https://jsfiddle.net/AHarmlessPyro/japzmLwo/10/
Actual results:
On Firefox, the anchorNode is set to the container of the third/last element (of type document.ELEMENT_NODE), while the focusNode is set to the text of the third/last element (of type document.TEXT_NODE).
Expected results:
Regardless of whether the selection is of type document.ELEMENT_NODE or document.TEXT_NODE, the anchor node should belong to the first element, not the third/last element. This (expected) behavior is observed on chrome for example.
Comment 1•1 year ago
|
||
The Bugbug bot thinks this bug should belong to the 'Core::DOM: Selection' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.
Comment 2•1 year ago
|
||
Probably the nodes are collapsed into a single point. Let me check
Comment 3•1 year ago
|
||
So basically because there are non selectable nodes in between, we split the selection into two ranges to exclude the non-selectable nodes. You can do getSelection().getRangeAt(0)
and getSelection().getRangeAt(1)
to see the two ranges. getSelection()
just returns second range.
It doesn't look like there's an easy fix here.
Description
•