Open bokand opened 1 year ago
What does 3 mean? Ideally this matches :target
behavior I think, which I think argues for 2.
3 means that the highlight is created with a Range (node A offset a, node B offset b) and we continue to highlight that range even if the content within it changes, though we'd have to decide what to do at range boundaries (node A or B are removed or their content changed to make the offset invalid)
2 is the most intuitive and is consistent with :target
but would require, for each highlight, to observe a (potentially-large) subtree for mutations (I guess option 1 also has this) and re-perform the text search each time. I don't have a great intuition for how expensive a mutation observer can be or how often mutations might fire but that makes me a bit worried. The text search could be performed over a limited subtree (e.g. the :target
which is the first common ancestor of the starting and ending node of the highlight) and without context but that could still be a non-trivial tree walk.
Fair, @megangardner thoughts about this?
Presumably we have this problem with find-in-page and various other features as well. Perhaps consistency with them should be sought rather than :target
. Hmm.
e.g. Jake's example from https://github.com/WICG/scroll-to-text-fragment/issues/217#issuecomment-1496217320: https://output.jsbin.com/vohimek/3/quiet
Chrome's behavior of keeping parts of the highlight across a word is clearly poor but the spec doesn't specify any behavior here.
We could specify:
I slightly lean to option 1 since it means the highlighted text is always what was searched for but wouldn't be opposed to option 3.