Selection.direction's value is incorrect
Categories
(Core :: DOM: Selection, defect)
Tracking
()
Tracking | Status | |
---|---|---|
firefox128 | --- | fixed |
People
(Reporter: stumpfmozessm, Assigned: sefeng)
References
(Regressed 1 open bug)
Details
Attachments
(1 file)
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36
Steps to reproduce:
Select a node and check the Selection.direction's value
Demo: https://codepen.io/IDontHaveAny/pen/bGywOwZ
Actual results:
If the Selection is collapsed, the direction is "forward"
On double click: it selects a word and the direction will be "none"
Expected results:
When the selection is collapsed, the direction is should be "none".
When selecting a word with double click, the selection should be "forward" because the anchor
is before the focus
.
Comment 1•4 months 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•4 months ago
|
||
Hi Sean, didn’t you work on this during your shadow DOM selection work?
Assignee | ||
Comment 3•4 months ago
|
||
Updated•4 months ago
|
Assignee | ||
Comment 4•4 months ago
|
||
Thanks for the bug! I agree with one of the expected results.
When the selection is collapsed, the direction is should be "none".
This makes sense, the submitted patch is for fixing this.
When selecting a word with double click, the selection should be "forward" because the anchor is before the focus.
The selection API defines the direction based on how the selection was created by users. If the user makes a "forward" selection, it's "forward", and vise versa. For the double click case, the selection was indeed "directionless" because the user didn't make any direction, so it should return "none" in my opinion. It would be a spec issue if we want to change it.
Reporter | ||
Comment 5•4 months ago
|
||
The selection API defines the direction based on how the selection was created by users. If the user makes a "forward" selection, it's "forward", and vise versa.
Selection API documentation:
If the user creates a selection by indicating first one boundary point of the range and then the other, and the first indicated boundary point is after the second, then the corresponding selection must initially be backwards. If the first indicated boundary point is before the second, then the corresponding selection must initially be forwards. Otherwise, it must be directionless.
Based on the documentation, it only considers the direction
based on the positions of the boundary-points.
For the double click case, the selection was indeed "directionless" because the user didn't make any direction, so it should return "none" in my opinion. It would be a spec issue if we want to change it.
Logically, there is no direction in the case of a double-click. Even though I have been working on a contenteditable
project for a while, and I haven't seen any use case where it could be useful. I think the only useful case for direction would be to determine the direction of the boundary-points based on their positions.
Assignee | ||
Comment 6•4 months ago
|
||
But we are talking about the indicated boundary point
and in this case the user makes both boundaries at the same location right? So I still think Firefox is doing what the spec says.
Regardless, this should be spec issue. Do you mind file one to https://github.com/w3c/selection-api to clarify?
Reporter | ||
Comment 7•4 months ago
|
||
I've opened one
https://github.com/w3c/selection-api/issues/177
Updated•4 months ago
|
Comment 11•4 months ago
|
||
bugherder |
Description
•