Documentation
¶
Overview ¶
Package cursor translates between text offsets and terminal cells. Standard widgets publish a collapsed DOM selection for the engine to position the hardware cursor. Custom editors and canvases can override that selection for one frame through doc.Terminal().Cursor(). Without either, the cursor is hidden.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ByteOffsetAtPoint ¶
ByteOffsetAtPoint translates a terminal-cell coordinate (targetX, targetY) relative to the IFC fragment tree's origin into a byte offset.
func FromTextFragment ¶
FromTextFragment translates a byte offset within an IFC fragment tree into a terminal-cell coordinate (x, y) suitable for positioning the hardware cursor.
Fragment tree structure ¶
root is the block-level fragment produced by the inline formatting context (IFC). Its direct children (root.Children) are line-box fragments — one per visual line. Each line-box fragment may contain one or more text-run child fragments (Fragment.Text != nil) and/or atomic-inline children (non-text fragments whose Size.Width contributes to the visual column offset but whose byte count is zero).
Algorithm ¶
Y-axis: the function iterates root.Children (line boxes) and accumulates the total byte length of each line by summing len(cluster.Bytes) for every text cluster in every text-fragment descendant. The first line whose cumulative byte total causes the running byte sum to reach or exceed byteOffset yields y.
X-axis: within the matching line box, text-fragment children are walked in order. For each text.Cluster, CellWidth is accumulated until the cluster whose byte range encloses byteOffset is reached. The accumulated cell-width before that cluster is x.
Atomic inlines: non-text child fragments contribute 0 bytes and their Size.Width cells to the visual X. This handles inline-block elements that appear before or between text runs.
Trailing offset: when byteOffset equals the total byte length of the fragment tree, the function returns the cell position immediately after the last cluster on the last line (x past the last glyph, y at the last line).
Return values ¶
Returns (x, y, true) on success. Returns (0, 0, false) if root is nil, the tree contains no children, or byteOffset exceeds the total byte length of the fragment tree.
TSK-023 ¶
This is the canonical cursor-positioning helper introduced in TSK-023. It replaces bespoke per-widget cursor math that was duplicated across render objects such as render.Input and render.TextArea.
Types ¶
This section is empty.