pub struct Selection {
pub anchor: Position,
pub focus: Position,
}Expand description
Document-level selection. Two positions — anchor at the
start of the interaction (e.g., mousedown, Shift+Click origin)
and focus at the current cursor position.
Direction-preserving: anchor may come before OR after
focus. Dragging backward shrinks / inverts the selection
without losing the original anchor.
Use Selection::caret for a collapsed selection (cursor
between two graphemes, no text highlighted).
Fields§
§anchor: Position§focus: PositionImplementations§
Source§impl Selection
impl Selection
Sourcepub fn new(anchor: Position, focus: Position) -> Self
pub fn new(anchor: Position, focus: Position) -> Self
Construct with explicit anchor + focus. Can be inverted (focus before anchor in document order).
Sourcepub fn caret(pos: Position) -> Self
pub fn caret(pos: Position) -> Self
Construct a collapsed selection (caret) at pos.
anchor == focus == pos.
Sourcepub fn is_collapsed(&self) -> bool
pub fn is_collapsed(&self) -> bool
true iff anchor == focus — no text is highlighted; the
selection represents a caret position only.
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
Mutably borrows from an owned value. Read more