Skip to main content

Module movement

Module movement 

Source
Expand description

Caret movement — the motions and the two combinators that apply them to a SelectionSet.

Motions are pure functions of the buffer and a position; the combinator move_selections maps one over every selection, either moving (collapse to a caret) or extending (drag the head, anchor fixed). Two details worth knowing: a plain horizontal move over a non-empty selection collapses to its near edge (not one char further), and vertical motion carries a goal column so travelling across short lines returns to the original column — the affinity editors are judged on.

Horizontal positions here are byte columns, but the vertical goal is a display cell: the caret keeps its visual column through tab stops, collapsed inline folds, and collapsed block placeholders, resolved on landing by the same inverse projection a mouse click uses.

Enums§

ColumnDir
A direction for column (box) selection — Ctrl+Shift+Alt+Arrow. Up/ Down move the active row; Left/Right move the active (virtual) column.
Granularity
Drag/selection granularity — the unit a click-drag extends by: single characters, whole words, or whole lines.
Motion
A caret motion.

Functions§

move_selections
Apply motion to every selection in set. With extend, each selection’s head moves and its anchor stays (grow/shrink); without, each collapses to a caret at the motion target. Re-merges afterward (a move can make two selections coincide). tab is the document’s tab-stop width — vertical motion keeps a visual goal column, so it needs the display projection.