Add Cluster::from_point_exact method for hit-testing spans #447
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Motivation
The existing
Cluster::from_pointmethod is tuned for text-selection / caret positioning where in the case that the cursor is not positioned exactly above a cluster, you usually want to position the caret (or selection anchor/focus) relative to the nearest cluster.For example if you click the empty space at the end of a left-aligned line of text in an editable textbox, then you would expect the caret to be positioned at the end of the line of text.
However, this logic doesn't work very well when hit-testing clusters for "hover" or "click" functionality (e.g. click a link within a paragraph of text). In that case you usually simply want to return
Nonein the case that the cursor is not directly over a cluster.Changes made
Cluster::from_pointinto a new private functionCluster::from_point_implthat takes a boolean parameter which determines whether or not the match should be exact (good for hit-testing click/hover) or not (the existing functionality - good for text selection).Cluster::from_pointsimply call intoCluster::from_point_implwithexact: falseCluster::from_point_exactthat calls intoCluster::from_point_implwithexact: trueThis PR is non-breaking
Videos
Before:
Screen.Recording.2025-10-30.at.20.40.46.mp4
After:
Screen.Recording.2025-10-30.at.20.39.02.mp4