pub enum Selection {
Char {
anchor: Position,
head: Position,
},
Line {
anchor_row: usize,
head_row: usize,
},
Block {
anchor: Position,
head: Position,
},
}Expand description
First-class vim selection. Each variant carries the kind directly
rather than relying on a single char-range primitive with separate
“treat as line / block” overlays — that’s the whole point of
owning the buffer model. Anchor is where the user pressed
v / V / Ctrl-V; head moves with the cursor and is updated
via Selection::extend_to.
Variants§
Char
v — character-wise. Covers anchor..=head inclusive,
row-major. Empty rows in the middle of a multi-row span are
treated as having one virtual cell so the highlight is
visible (matches vim).
Line
V — line-wise. Both endpoints are pure row indices; column
is irrelevant (the whole row is always covered).
Block
Ctrl-V — block-wise. Covers the inclusive rectangle whose
corners are anchor and head. Row range is min..=max; column
range is min..=max independently of the corner diagonals.
Implementations§
Source§impl Selection
impl Selection
Sourcepub fn head(self) -> Position
pub fn head(self) -> Position
Where the cursor end of the selection lives. After
Selection::extend_to this is the freshly-set value.
Sourcepub fn anchor(self) -> Position
pub fn anchor(self) -> Position
The opposite end of the selection — fixed when the user entered visual mode.
Sourcepub fn extend_to(&mut self, pos: Position)
pub fn extend_to(&mut self, pos: Position)
Move the cursor end of the selection to pos. Anchor stays
put; for Line we drop the column since rows are all that
matter.
Sourcepub fn row_span(self, row: usize) -> RowSpan
pub fn row_span(self, row: usize) -> RowSpan
What columns of row the selection covers. Used by the
render layer to paint the selection bg without having to
know each variant’s quirks.
Charon a single row:[min_col, max_col].Charspanning rows: fromhead/anchor.colon the start row to end-of-line, then full rows in between, then0..=end.colon the last row.Line:(0, usize::MAX)for every row in range.Block:[min_col, max_col]regardless of which row.
Sourcepub fn row_bounds(self) -> (usize, usize)
pub fn row_bounds(self) -> (usize, usize)
Inclusive (top_row, bottom_row) covered by the selection.