Closed Bug 2043324 Opened 21 days ago Closed 7 days ago

Text Fragments: Creating a text fragment inside a container that has ::before doesn't find other matches in that container

Categories

(Core :: DOM: Core & HTML, defect)

defect

Tracking

()

RESOLVED FIXED
153 Branch
Tracking Status
firefox153 --- fixed

People

(Reporter: jjaschke, Assigned: jjaschke)

Details

Attachments

(2 files)

Attached file minimal-testcase

STR: Open the attached example. Select the second "test", then open the context menu and click "Copy Link to Highlight".

Expected results: the created text fragment should be :~:text=foo-,test
Actual results: the created text fragment is :~:text=test, which also matches the first "test" inside the div.

Analysis:
nsFind uses ComparePoints() to figure out when it reached the end point. ComparePoints() does not work well with things like NAC or shadow DOM -- it will just return Some(1) in that case, which translates to "the NAC/Shadow DOM is after the node", which causes the Text Fragments algorithm to stop. Therefore it doesn't see the first "test" in the <div>, and the algorithm fails.

Attachment #9591097 - Attachment filename: file_2043324.txt → testcase.html

The endpoint check in nsFind uses ComparePoints to determine if
the current position is past the search boundary.
However, CompareClosestCommonAncestorChildren (used by ComparePoints)
returns Some(1) for NAC roots, incorrectly treating ::before content as
"after" regular children. This causes nsFind to exit early, missing
valid matches that follow the ::before in document order.

When the current node is in a native anonymous subtree and is not a
descendant of the endpoint container, use CompareTreePosition instead.
CompareTreePosition handles NAC correctly via GetIndexInParent, which
assigns proper indices to pseudo-elements matching the flat tree order.

Attachment #9591175 - Attachment description: Bug 2043324 - Text Fragments: Fix nsFind endpoint check for native anonymous content. r=emilio! → Bug 2043324 - Order native anonymous content correctly in ComparePoints. r=emilio!
Status: ASSIGNED → RESOLVED
Closed: 7 days ago
Resolution: --- → FIXED
Target Milestone: --- → 153 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: