You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Moving ability to highlight from HighlightRange into Range allows to highlight already selected text, without the need of recreating the range.
Having yet another global collection (alongside e.g. customElements) seems like overkill for most of the cases. What's more, if we must have saved reference to the range to be able to remove it from HighlightsMap, then we could as well do it on range level.
HTMLElement has its own style property, which contains all styles associated directly to the element. Analogically Range can have its own property connected with highlighting.
HighlightList is based on DOMTokenList (used in e.g. element.classList). The main difference is the changed behavior of remove method, which will remove all highlights if called without parameters.
Issues
There seems to be a fundamental incompatibility between the new Highlight API and Selection API. The first one allows to have multiple ranges rendered at once in several places on the screen, while the latter allows only one-range selection. If browsers supported multiple-range selection, we would be able to extend Selection interface with highlight abilities.
Adding HighlightList to Range interface allows range to decide, when it will be rendered. It could be seen as a breach of SRP: Range should not decide about it. OTOH it won't be a precedence, as HTMLElement has methods like append or remove. Additionally, due to this change, API for highlighting will be much simpler and contained.