Skip to content

highlightsFromPoint now also returns ranges hit #1056

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ffiori
Copy link
Member

@ffiori ffiori commented Jun 6, 2025

As discussed and resolved in w3c/csswg-drafts#12031, this PR changes the return type for highlightsFromPoint to sequence to include the ranges that are hit at a given point in addition to the custom highlights.

There are updates to the customer problem example to now show a spellchecker, and several updates throughout description and example code.

@ffiori ffiori requested review from dandclark and leotlee June 6, 2025 21:55
- There's no need to iterate over all the ranges of the highlights registered anymore, now `highlightsFromPoint` gives us only the highlights that are under the point `(x,y)`.
- There's no need to deal with ranges and rectangles anymore because that's handled by the API.
- There's no need to iterate over all the ranges of the highlights registered anymore, now `highlightsFromPoint` gives us only the highlights and ranges that are under the point `(x,y)`. Note that in this particular example we know that if a highlight is hit, there's only one range that was hit because there's no overlapping ranges in the spellchecker.
- There's no need to deal with creating new Ranges and rectangles anymore because that's handled by the API.
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason why "Ranges" is capitalized?

Copy link
Member Author

@ffiori ffiori Jun 10, 2025

Choose a reason for hiding this comment

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

Oh, I forgot to surround it with ticks to give it a monospace style. I wanted to emphasize I'm talking about live ranges (Range type). I'll update it to look like that (like line 79). Thanks


When the mouse click event happens outside of the higlights, the performance profiler from developer tools shows that `createActiveHighlights` takes more time dealing with the ranges and getting the rectangles compared to the version that uses `highlightsFromPoint`. And when the event happens on a highlight, the call to `highlightsFromPoint` takes less time than all the necessary calls to `getClientRects` that are fired in the version that doesn't use the new API. Both measurements indicate that using the new API gives a performance advantage by getting rid of all the Javascript overhead that the program requires when implementing this use case with the current APIs available.
When the mouse click event happens outside of the higlights, the performance profiler from developer tools shows that `createActiveHighlights` takes more time dealing with the Ranges and getting the rectangles compared to the version that uses `highlightsFromPoint`. And when the event happens on a highlight, the call to `highlightsFromPoint` takes less time than all the necessary calls to `getClientRects` that are fired in the version that doesn't use the new API. Both measurements indicate that using the new API gives a performance advantage by getting rid of all the Javascript overhead that the program requires when implementing this use case with the current APIs available.
Copy link
Contributor

Choose a reason for hiding this comment

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

"Ranges"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants