Skip to content

Conversation

@nicoburns
Copy link
Collaborator

Motivation

The existing Cluster::from_point method 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 None in the case that the cursor is not directly over a cluster.

Changes made

  • Move the implementation of Cluster::from_point into a new private function Cluster::from_point_impl that 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).
  • Make Cluster::from_point simply call into Cluster::from_point_impl with exact: false
  • Add a new public function Cluster::from_point_exact that calls into Cluster::from_point_impl with exact: true

This 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
Signed-off-by: Nico Burns <nico@nicoburns.com>
Copy link
Collaborator

@dfrg dfrg 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 the detailed explanation. LGTM

@nicoburns nicoburns added this pull request to the merge queue Oct 31, 2025
Merged via the queue into linebender:main with commit aa2bfa6 Oct 31, 2025
23 checks passed
@nicoburns nicoburns deleted the exact-cluster-from-point branch October 31, 2025 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants