Skip to content

Editorial review: Add docs for the HighlightRegistry.highlightsFromPoint() method #40390

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

Merged

Conversation

chrisdavidmills
Copy link
Contributor

Description

Chrome 140 adds support for the HighlightRegisty.highlightsFromPoint() method; see https://chromestatus.com/feature/4552801607483392.

This PR adds docs for the new method.

The Spec and browser compat tables are not currently showing, but will soon. The necessary data is added in mdn/browser-compat-data#27310.

Motivation

Additional details

Related issues and pull requests

@chrisdavidmills chrisdavidmills requested a review from a team as a code owner July 16, 2025 15:50
@chrisdavidmills chrisdavidmills requested review from sideshowbarker and removed request for a team July 16, 2025 15:50
@github-actions github-actions bot added Content:WebAPI Web API docs size/m [PR only] 51-500 LoC changed labels Jul 16, 2025
Copy link
Contributor

github-actions bot commented Jul 16, 2025

Preview URLs

(comment last updated: 2025-07-23 13:54:24)

@chrisdavidmills chrisdavidmills changed the title Add docs for the HighlightRegistry.highlightsFromPoint() method Technical review: Add docs for the HighlightRegistry.highlightsFromPoint() method Jul 16, 2025
@chrisdavidmills chrisdavidmills removed the request for review from sideshowbarker July 16, 2025 15:53
Copy link

@ffiori ffiori left a comment

Choose a reason for hiding this comment

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

Thanks for working on this article! I left some comments after a first review but it's looking great.

@chrisdavidmills chrisdavidmills requested a review from ffiori July 17, 2025 07:11
@chrisdavidmills
Copy link
Contributor Author

Thanks for the review, @ffiori! I've responded to all your comments. Please let me know if you think this needs anything else, or give me a "LGTM" if you think it is ready to go to the editorial review stage.

Copy link

@ffiori ffiori left a comment

Choose a reason for hiding this comment

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

Left a couple comments after reviewing the new version. And thanks for addressing the previous ones, it's looking really good!

@chrisdavidmills
Copy link
Contributor Author

That's the last few bits of cleanup dealt with; thanks @ffiori for taking the time to provide me with a great tech review.

I think this is now ready to go to the editorial review stage.

@chrisdavidmills chrisdavidmills changed the title Technical review: Add docs for the HighlightRegistry.highlightsFromPoint() method Editorial review: Add docs for the HighlightRegistry.highlightsFromPoint() method Jul 18, 2025
@ffiori
Copy link

ffiori commented Jul 18, 2025

That's the last few bits of cleanup dealt with; thanks @ffiori for taking the time to provide me with a great tech review.

I think this is now ready to go to the editorial review stage.

Agreed, LGTM! Thanks for addressing all the feedback and putting all this together :)

(I can't hit approve because it seems I don't have the permissions to do so in this repo but consider it approved by me)

@estelle estelle self-assigned this Jul 21, 2025
Copy link
Member

@estelle estelle left a comment

Choose a reason for hiding this comment

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

The example is a good one, but there is so much that needs to happen to demonstrate this feature. I think it might be helpful to explain that the example is really two parts; the first step is creating the custom highlights, and the second is the point of the page, basically state that "this part isn't just so we can do the relevant part" (and maybe add a link there to the the create custom highlight examples, and to the page we just added yesterday).

There are a few minor edits too.

All the other edits are me trying to shrink the example. I did a CodePen, to hopefully reduce the complexity and shrink the explanation. See https://codepen.io/estelle/pen/jEbqrxx. I highlighted the edits i made so you know what to look for.Please take a look at the codepen suggested shrinkage before reading all the code change suggestions. Then hopefully the feedback below won't be overwhelming.

I did comment where I made suggested changes in that codepen. There are several variable name suggestions in the codepen.

@chrisdavidmills chrisdavidmills requested a review from estelle July 23, 2025 09:59
Copy link
Member

@estelle estelle left a comment

Choose a reason for hiding this comment

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

Looks good. I think it would be helpful to divide the example explanation into two parts, so I suggested a way of doing that... your text may vary.

Otherwise, LGTM.


#### JavaScript

We start by grabbing references to the `<p>` element, its contained text node, and our `<section>` element. We then create a variable called `highlightCount`, initially set to `1`, which will be used to specify which custom highlight to apply later on.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
We start by grabbing references to the `<p>` element, its contained text node, and our `<section>` element. We then create a variable called `highlightCount`, initially set to `1`, which will be used to specify which custom highlight to apply later on.
##### Create custom highlights
To create custom highlights, we start by grabbing references to the `<p>` element, its contained text node, and our `<section>` element. We then create a variable called `highlightCount`, initially set to `1`, which will be used to specify which custom highlight to apply later on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this is quite a nice suggestion — see my next commit. I have also moved the section global definition into the second section, so it is right by the point where it gets used.

```

#### JavaScript

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
To demonstrate the `highlightsFromPoint()` method, we need to have some highlights that can be returned.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

});
```

Next, we define a [`dblclick`](/en-US/docs/Web/API/Element/dblclick_event) event handler function to handle outputting the highlighted text at the mouse cursor position when the event fires. We pass the current mouse coordinates into a `highlightsFromPoint()` call, clear the contents of the `<section>` element, then loop through each highlight in the `highlights` array.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Next, we define a [`dblclick`](/en-US/docs/Web/API/Element/dblclick_event) event handler function to handle outputting the highlighted text at the mouse cursor position when the event fires. We pass the current mouse coordinates into a `highlightsFromPoint()` call, clear the contents of the `<section>` element, then loop through each highlight in the `highlights` array.
##### Returning custom highlights from a point
Now that we have the ability to create custom highlights, we can use the highlightsFromPoint() method to return custom highlights from a defined point.
We define a [`dblclick`](/en-US/docs/Web/API/Element/dblclick_event) event handler function to handle outputting the highlighted text at the mouse cursor position when the event fires. We pass the current mouse coordinates into a `highlightsFromPoint()` call, clear the contents of the `<section>` element, then loop through each highlight in the `highlights` array.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@chrisdavidmills chrisdavidmills requested a review from estelle July 23, 2025 13:54
Copy link
Member

@estelle estelle left a comment

Choose a reason for hiding this comment

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

Yay!

@estelle estelle merged commit be4e435 into mdn:main Jul 23, 2025
8 checks passed
@chrisdavidmills chrisdavidmills deleted the highlightregistry-highlightsfrompoint branch July 23, 2025 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:WebAPI Web API docs size/m [PR only] 51-500 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants