Skip to main content

SelectionSet

Struct SelectionSet 

Source
pub struct SelectionSet { /* private fields */ }
Expand description

A non-empty, sorted, disjoint set of selections. Merged after every mutation so no two selections overlap.

Implementations§

Source§

impl SelectionSet

Source

pub fn new(offset: u32) -> Self

A set with a single caret at offset.

Source

pub fn from_offsets(offsets: &[u32]) -> Self

A set of carets at the given offsets (merged). Used by the verbs layer to place carets after an edit. Panics if offsets is empty — a set is never empty.

Source

pub fn from_ranges(ranges: &[(u32, u32)], newest: usize) -> Self

Build a set from (anchor, head) ranges (any order); the range at index newest becomes the primary (largest id) — the autoscroll target. Used to install a column (box) selection. Panics if ranges is empty or newest is out of bounds.

Source

pub fn all(&self) -> &[Selection]

The selections, in document order.

Source

pub fn len(&self) -> usize

How many selections (always ≥ 1).

Source

pub fn is_empty(&self) -> bool

Always false — a set is never empty. Present for lint-friendliness alongside SelectionSet::len.

Source

pub fn newest(&self) -> &Selection

The newest selection (largest id) — the autoscroll / primary target.

Source

pub fn add_caret(&mut self, offset: u32)

Add a caret at offset, merging into any selection it touches.

Source

pub fn add_selection(&mut self, anchor: u32, head: u32)

Add a selection from anchor to head, merging as needed.

Source

pub fn set_single(&mut self, sel: Selection)

Replace the whole set with a single selection (Escape collapses to the oldest; here the caller supplies it).

Source

pub fn collapse_to_newest(&mut self)

Collapse to just the newest selection, as a caret at its head (the standard Escape behavior for multi-cursor).

Source

pub fn collapse_to_primary(&mut self)

Collapse to just the oldest selection (smallest id), as a caret at its head — the multi-cursor Escape that keeps the primary cursor. With a single ranged selection this simply deselects it to a caret.

Source

pub fn map_each(&mut self, f: impl FnMut(&mut Selection))

Mutate every selection through f, then re-merge. The building block for movement.

Source

pub fn rebase(&mut self, patch: &Patch)

Rebase every selection through an edit’s Patch — the eager mover that keeps every endpoint current as text is inserted and deleted. Endpoints use Left bias for the start and Right for the end so a selection grows over text typed at its edges; carets follow the insertion. Re-merges afterward.

Trait Implementations§

Source§

impl Clone for SelectionSet

Source§

fn clone(&self) -> SelectionSet

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SelectionSet

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.