pub struct Selection {
pub anchor: Position,
pub head: Position,
pub visual: Option<VisualMode>,
}Expand description
One cursor or visual extent in a buffer.
anchor and head are not ordered: moving backwards in Visual mode puts
head before anchor, and consumers normalise (min/max) when they need
a span. With visual set, the extent follows vim’s
inclusive convention — Charwise covers the character at head too (a
renderer converts to a half-open Range by extending
end one character), Linewise covers whole lines regardless of the byte
columns, and Blockwise covers the rectangle the two corners span.
§Examples
use lattice_protocol::{Position, Selection, VisualMode};
let caret = Selection::cursor(Position::new(4, 2));
assert!(caret.is_cursor());
// A backwards charwise selection: head precedes anchor.
let backwards = Selection {
anchor: Position::new(0, 8),
head: Position::new(0, 3),
visual: Some(VisualMode::Charwise),
};
assert!(!backwards.is_cursor());
assert!(backwards.head < backwards.anchor);Fields§
§anchor: PositionThe fixed end — where Visual mode was entered. Equals head for a
plain cursor.
head: PositionThe moving end: the cursor the user sees and motions move.
visual: Option<VisualMode>The visual-mode shape of the extent, or None outside Visual mode.
Implementations§
Trait Implementations§
impl Copy for Selection
Source§impl<'de> Deserialize<'de> for Selection
impl<'de> Deserialize<'de> for Selection
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.