Skip to main content

Module hit_test

Module hit_test 

Source
Expand description

W3.4: pointer -> caret hit-test + word/line expansion.

No-dep helpers - these run without needing a shaped layout (the caller passes the text and an approximate average advance) so they’re usable from unit tests and from the input crate even when no shaper is wired (e.g. headless tests).

The real shaping-aware hit-test path is intended to consult the per-entity ShapedRunIndex cache (W3.6) - once that exists, the input crate can ask the shaper for xy_to_byte(x, y) and feed the result through select_word_at_byte / select_line_at_byte unchanged.

Functions§

hit_test_text
Hit-test against a single-line run with a uniform per-char advance. Returns the byte offset whose glyph the pointer landed nearest.
next_word_boundary
Byte offset of the end of the Unicode-word segment at/after from. See prev_word_boundary.
prev_word_boundary
Byte offset of the start of the Unicode-word segment strictly before from. Used for directional word motion (ctrl+<-, ctrl+Backspace) - shares the split_word_bound_indices walk select_word_at_byte uses to expand a point into a range, but returns the boundary itself rather than a (start, end) pair.
select_line_at_byte
Expand a byte offset into a line range. \n is excluded from the end of the range so a triple-click select-then-replace doesn’t eat the newline.
select_word_at_byte
Expand a byte offset into a word range using Unicode word boundaries. Returns (start, end) in bytes; start == end == byte when the click landed on whitespace.