SelectionHitTest
Line and codepoint navigation helpers shared by the caret hit-test path (UniTextBase.HitTestCaret), the editing layer (vertical caret movement, line edges), and selection-extension code.
Remarks
public static int FindLineAtLocalPoint(Vector2 localPos, Rect textRect, UniTextBuffers buffers)Determines which text line corresponds to the given local-space point. textRect must be the rect the glyph coordinates are relative to (the padded rect).
public static int FindLineAtCodepoint(int codepointIndex, PooledBuffer<TextLine> lines, bool upstream = false)Finds the line containing a given codepoint via binary search. With upstream set, codepoints that sit at a soft-wrap boundary resolve to the upstream line (useful for caret affinity).
public static int FindCodepointAtX(UniTextBase uniText, int lineIndex, float targetX, PooledBuffer<TextLine> lines)Finds the codepoint index on lineIndex closest to targetX in text-local coordinates. Snaps to grapheme cluster boundaries to keep multi-codepoint sequences atomic. Never returns a position past a trailing mandatory break (see LineCaretEnd). Scans only the line's own glyph span (TextLine.glyphStart/TextLine.glyphCount) — the per-call cost is bounded by the line, not the document. Clicks past a visual line edge resolve to the logical line start / end when the edge run follows the paragraph direction, otherwise to the edge glyph's BiDi codepoint (the visual edge — Android getOffsetForHorizontal / Chromium PositionForPoint behavior on mixed-direction lines).
