Expand description
Native-grade text selection primitives for BasicTextField.
This module holds the pure, unit-tested building blocks the text field uses to offer Android/iOS-style selection: tap-count classification, word and line/paragraph boundary detection, and the geometry of the draggable teardrop selection handles (their shapes, their hit regions, and the selection math that a handle drag produces).
Keeping these as free functions makes the touch behavior testable without a
renderer and keeps TextFieldModifierNode focused on wiring.
Enums§
- Handle
Kind - Which selection handle a teardrop represents.
- TapCount
- How many consecutive taps a press represents, mirroring the platform text selection gestures: one tap places the cursor, two select the word, three select the line/paragraph.
Constants§
- HANDLE_
RADIUS - Radius of a selection/cursor handle bulb in px (Android uses ~11dp).
- HANDLE_
TOUCH_ PADDING - Extra padding (px) added around a handle’s drawn teardrop to enlarge the finger touch target, matching Android’s generous handle hit area.
- HANDLE_
TOUCH_ SLOP - Extra hit-test slop (px) around a handle so it is easy to grab with a finger.
- MULTI_
TAP_ SLOP_ PX - Maximum distance (px) between consecutive taps that still counts as a
multi-tap. A tap that lands far from the previous one starts a fresh
single tap even if it arrives quickly, matching Android’s
ViewConfigurationdouble-tap slop behavior. - MULTI_
TAP_ TIMEOUT_ MS - Maximum time between taps that still counts as a multi-tap, in milliseconds.
Functions§
- classify_
tap - Classifies a press into a tap count from the previous tap’s count, the time since it, and the distance from it.
- find_
line_ boundaries - Returns the byte range
[start, end)of the line/paragraph containingpos, delimited by\n(the newline itself is excluded from the range). - handle_
hit_ rect - The axis-aligned hit region for a handle, expanded by touch slop, used to decide whether a pointer-down grabbed a handle.
- handle_
path_ data - SVG path data for a handle teardrop whose tip sits at
(tip_x, tip_y). - hit_
test_ handles - Returns the handle nearest to
(x, y)whose slop-expanded hit region contains the point, orNonewhen the point misses every handle. - selection_
after_ handle_ drag - Computes the selection
(min, max)that results from dragging one handle to a new textoffset, keeping the opposite (fixed) edge anchored.