Skip to main content

Module selection

Module selection 

Source
Expand description

Selections and the multi-cursor set.

A Selection is a byte-offset range with a direction: start <= end always, and reversed says which end the caret (the head) is on, so the set is always stored in document order while the caret can face either way. Empty selections (start == end) are bare carets.

A SelectionSet holds one or more disjoint selections, kept sorted and merged. Multi-cursor is a first-class model concept: the gestures that add cursors live in the UI layer, and this is the data they act on. Selections rebase through every edit’s Patch eagerly, so a caret is always the current position and never a stale copy of an offset from before the edit.

Structs§

Selection
A directional byte-offset range. start <= end is an invariant; reversed records whether the caret is at start (true) or end (false).
SelectionId
Identity for a selection, monotonic within a SelectionSet. Larger ids are newer; used to pick the newest (autoscroll target) and oldest (Escape).
SelectionSet
A non-empty, sorted, disjoint set of selections. Merged after every mutation so no two selections overlap.