Open Bug 1504633 Opened 2 years ago Updated 2 years ago

`selection.anchorNode` incorrectly returns outer div node, should return text node


(Core :: DOM: Selection, defect, P3)

63 Branch





(Reporter: assaf.urieli, Unassigned)


User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:63.0) Gecko/20100101 Firefox/63.0

Steps to reproduce:,console,output

Actual results:

`selection.anchorNode` is the outer div node
`range.startContainer` is the outer div node
`range.endContainer` is the text in the following span

Expected results:

`selection.anchorNode` should be the text node containing the highlighted text or at worst span just surrounding it
`range.startContainer` should be the same as selection.anchorNode
`range.endContainer` should be the same as selection.anchorNode
Just realized this is because Firefox is including the empty preceding span node in the selection.

Not sure if this should be considered a bug.

If a selection starts just after an empty span, then the parent element is currently considered to be the anchor node.

It would be more intuitive not to include preceding empty spans in the selection.
I tried to reproduce this bug on Ubuntu 16.04, Mac OS X 10.13 and on Windows 10.

On Ubuntu 16.04 and Mac OS X 10.13 I compered Firefox 65.0a1 and Firefox 63.0.1 with chrome and the results were the same, when I double click on "Called" or "the" only the text is highlighted.

But on Windows 10 x64 when I double click on "Called" or "the" the text is highlighted and also an extra space.

I'm not sure if this is the intended results or not? Could you please let me know if you see something different?
Flags: needinfo?(assaf.urieli)
I personally think only the text should be highlighted, without an extra space.

However, this bug in particular concerned the value of `selection.anchorNode`, rather than what is selected on a double-click.

In particular, when you double-click on text which is preceded by a <br> and an empty <span>, should the empty span be considered as part of the selection?
Personally, I think it shouldn't, but this is open to interpretation.

This new bin illustrates the question better:,console,output

When you click on the first "here", the anchorNode is the text.
When you click on the second "here", the anchorNode is the surrounding div.
When you click on the third "here", the anchorNode is the text again.

The second "here" is preceded by both a <br> and an empty <span>
Flags: needinfo?(assaf.urieli)
I am going to assign the "Core: Selection" component for it and hopefully someone with more knowledge in this area will a look over this.
Component: Untriaged → Selection
Product: Firefox → Core
Priority: -- → P3
You need to log in before you can comment on or make changes to this bug.