WICG / scroll-to-text-fragment

Proposal to allow specifying a text snippet in a URL fragment
Other
589 stars 42 forks source link

[Spec] Incorrectly searches node data rather than rendered text #98

Open bokand opened 4 years ago

bokand commented 4 years ago

The find a range from a node list steps, which is the place in the spec where the actual string search is performed, uses the CharacterData of each node.

CharacterData is the raw data provided in the markup, e.g.:

<div>hello          world</div>

Will include all 10 spaces in CharacterData, even though they're collapsed into a single space when rendered.

The spec needs to specify exactly how we perform this collapsing.

zcorpan commented 10 months ago

Chromium currently seems to collapse whitespace both in generating a text fragment URL and when finding the target text. Demo: https://software.hixie.ch/utilities/js/live-dom-viewer/?saved=12210#:~:text=foo%20bar,-Markup%20to%20test

bokand commented 10 months ago

Yup, I noted in the discussion in #233 this was the intended behavior but I wasn't sure how to spec it correctly.

I think we want to preserve this behavior - e.g. an author changing the indentation level of an element (maybe because they added/removed an ancestor element) would break any links into that text (since the leading whitespace will change).

Lets use #233 to resolve this.