getSelection().toString() is inconsistent with its ranges
Categories
(Core :: DOM: Selection, defect)
Tracking
()
People
(Reporter: wblandin, Unassigned)
Details
(Keywords: testcase, Whiteboard: [bugday-20140113])
Comment 1•11 years ago
|
||
Comment 2•11 years ago
|
||
Reporter | ||
Comment 3•10 years ago
|
||
Updated•10 years ago
|
Comment 4•10 years ago
|
||
Reporter | ||
Comment 5•10 years ago
|
||
Comment 6•10 years ago
|
||
Comment 7•10 years ago
|
||
Reporter | ||
Comment 8•10 years ago
|
||
Comment 9•10 years ago
|
||
Comment 10•4 years ago
|
||
This behaviour is still present in Firefox 83. I want to contribute another test case to describe the selection behaviour: https://jsfiddle.net/
There, the string "M QMMQ M" is displayed, each character is wrapped in a span tag.
(1) As described above, depending on where the user starts a mousedown to select "QMMQ" the resulting range is either:
startContainer = " " / startOffset = 1, if the mousedown is occuring over the space before Q (while at the same time not selecting the space)
or
startContainer = "Q" / startOffset = 0, if the mousedown is occuring over the Q
It is unintuitive and inconsistent to get two different range results for the exact same visual selection.
(2) If the user double clicks the word QMMQ the resulting selection range is:
startContainer = " " / startOffset = 1 and endContainer = " " / startOffset = 0
which is also unintuitive. In that case, I would expect:
startContainer = "Q" / startOffset = 0 and endContainer = "Q" / startOffset = 1
Chromium handles these cases consistent and intuitively. Sure, there might be good reasons to handle the selection the firefox way, this is just a comment. A use case where the chromium behaviour is of advantage is if you have all characters wrapped in spans to annotate / highlight ranges of text using css. Having window.getSelection reliably return the text nodes which are the start and end of the visual selection helps here as one does not have to look at startOffset/endOffset and possible need to move to the next / previous sibling to get the correct span.
Comment 11•4 years ago
|
||
sorry, here is the correct link: https://jsfiddle.net/yoepq4dL/1/
The range is logged to the console when pressing the "show selection" button
Updated•2 years ago
|
Description
•