Skip to content

[Editing] Use dom selection anchor while extending the selection #53246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2025

Conversation

chromium-wpt-export-bot
Copy link
Collaborator

Currently, DOMSelection::extend uses the shadow-adjusted anchor node,
which causes the selection to collapse when extended within a shadow
tree. This change updates DOMSelection::extend to use the
SelectionInDOMTree anchor instead, ensuring that the selection can be
properly extended within shadow trees without collapsing.

As per the spec [1] the anchor node may or may not be part of the
shadow tree. In current implementation if we extend the selection
after DOMSelection::collapse the selection does extend but if we
extend after mouse click at same location in the shadow tree it
collapses. After this change the DOMSelection::extend behavior will
be consistent in both mouse click and DOMSelection::collapse cases and
this behavior also aligns with Webkit and Gecko.

[1] https://www.w3.org/TR/selection-api/#dfn-anchor

Bug: 421314614
Change-Id: I81c03931b80b795a90cc15ce5b5d79e50adf94da
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6631596
Reviewed-by: Kent Tamura <tkent@chromium.org>
Commit-Queue: Ashish Kumar <ashishkum@microsoft.com>
Reviewed-by: Sambamurthy Bandaru <sambamurthy.bandaru@microsoft.com>
Cr-Commit-Position: refs/heads/main@{#1475430}

Currently, DOMSelection::extend uses the shadow-adjusted anchor node,
which causes the selection to collapse when extended within a shadow
tree. This change updates DOMSelection::extend to use the
SelectionInDOMTree anchor instead, ensuring that the selection can be
properly extended within shadow trees without collapsing.

As per the spec [1] the anchor node may or may not be part of the
shadow tree. In current implementation if we extend the selection
after DOMSelection::collapse the selection does extend but if we
extend after mouse click at same location in the shadow tree it
collapses. After this change the DOMSelection::extend behavior will
be consistent in both mouse click and DOMSelection::collapse cases and
this behavior also aligns with Webkit and Gecko.

[1] https://www.w3.org/TR/selection-api/#dfn-anchor

Bug: 421314614
Change-Id: I81c03931b80b795a90cc15ce5b5d79e50adf94da
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6631596
Reviewed-by: Kent Tamura <tkent@chromium.org>
Commit-Queue: Ashish Kumar <ashishkum@microsoft.com>
Reviewed-by: Sambamurthy Bandaru <sambamurthy.bandaru@microsoft.com>
Cr-Commit-Position: refs/heads/main@{#1475430}
Copy link
Collaborator

@wpt-pr-bot wpt-pr-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The review process for this patch is being conducted in the Chromium project.

@chromium-wpt-export-bot chromium-wpt-export-bot merged commit b112b12 into master Jun 18, 2025
22 checks passed
@chromium-wpt-export-bot chromium-wpt-export-bot deleted the chromium-export-31116a7845 branch June 18, 2025 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants