Skip to main content

SelectionState

Struct SelectionState 

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

Deterministic selection state machine.

Tracks the interactive lifecycle of a selection over the combined terminal buffer (scrollback + viewport). All methods are pure: given the same inputs, they produce the same outputs.

Implementations§

Source§

impl SelectionState

Source

pub const fn new() -> Self

Create a new state machine with no active selection.

Source

pub fn phase(&self) -> SelectionPhase

Current phase of the selection lifecycle.

Source

pub fn current_selection(&self) -> Option<Selection>

Returns the current selection, normalized (start ≤ end).

Returns None when phase is None.

Source

pub fn raw_selection(&self) -> Option<Selection>

Returns the raw (non-normalized) selection for display purposes.

Source

pub fn anchor(&self) -> Option<BufferPos>

Returns the anchor point (drag start).

Source

pub fn granularity(&self) -> SelectionGranularity

Current selection granularity.

Source

pub fn shape(&self) -> SelectionShape

Current selection shape.

Source

pub fn has_selection(&self) -> bool

Whether any selection is present (selecting or active).

Source

pub fn start(&mut self, pos: BufferPos, granularity: SelectionGranularity)

Begin a new selection at pos.

Transitions: None → Selecting, Active → Selecting. Clears any previous selection.

Source

pub fn start_with_shape( &mut self, pos: BufferPos, granularity: SelectionGranularity, shape: SelectionShape, )

Begin a new selection with a specific shape.

Source

pub fn drag(&mut self, pos: BufferPos)

Update the selection endpoint during drag.

Only valid when phase == Selecting. The selection is updated from anchor to pos.

Source

pub fn drag_expanded( &mut self, pos: BufferPos, grid: &Grid, scrollback: &Scrollback, )

Update the selection with grid-aware expansion.

When granularity is Word or Line, expands the selection from the anchor word/line to the word/line containing pos.

Source

pub fn commit(&mut self)

Commit the current selection (mouse released).

Transitions: Selecting → Active. No-op if not selecting.

Source

pub fn cancel(&mut self)

Cancel and clear the selection.

Transitions: Any → None.

Source

pub fn toggle_shape(&mut self)

Toggle between linear and rectangular selection.

Preserves the current selection range, only changes shape.

Source

pub fn contains(&self, line: u32, col: u16) -> bool

Check if a cell at (line, col) is within the current selection.

Accounts for selection shape (linear vs rectangular).

Source

pub fn extract_text( &self, grid: &Grid, scrollback: &Scrollback, ) -> Option<String>

Extract text from the current selection using the grid and scrollback.

Returns None if no selection is active. For linear selections, delegates to Selection::extract_text. For rectangular selections, delegates to Selection::extract_rect.

Source

pub fn extract_copy( &self, grid: &Grid, scrollback: &Scrollback, opts: &CopyOptions, ) -> Option<String>

Extract text with explicit copy options.

Shape-aware: dispatches to linear or rectangular extraction based on the current selection shape.

Trait Implementations§

Source§

impl Clone for SelectionState

Source§

fn clone(&self) -> SelectionState

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for SelectionState

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for SelectionState

Source§

fn default() -> Self

Returns the “default value” for a type. 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.