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.
Trait Implementations§
impl Copy for Selection
impl Eq for Selection
impl StructuralPartialEq for Selection
Auto Trait Implementations§
impl Freeze for Selection
impl RefUnwindSafe for Selection
impl Send for Selection
impl Sync for Selection
impl Unpin for Selection
impl UnsafeUnpin for Selection
impl UnwindSafe for Selection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more