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
impl SelectionState
Sourcepub fn phase(&self) -> SelectionPhase
pub fn phase(&self) -> SelectionPhase
Current phase of the selection lifecycle.
Sourcepub fn current_selection(&self) -> Option<Selection>
pub fn current_selection(&self) -> Option<Selection>
Returns the current selection, normalized (start ≤ end).
Returns None when phase is None.
Sourcepub fn raw_selection(&self) -> Option<Selection>
pub fn raw_selection(&self) -> Option<Selection>
Returns the raw (non-normalized) selection for display purposes.
Sourcepub fn granularity(&self) -> SelectionGranularity
pub fn granularity(&self) -> SelectionGranularity
Current selection granularity.
Sourcepub fn shape(&self) -> SelectionShape
pub fn shape(&self) -> SelectionShape
Current selection shape.
Sourcepub fn has_selection(&self) -> bool
pub fn has_selection(&self) -> bool
Whether any selection is present (selecting or active).
Sourcepub fn start(&mut self, pos: BufferPos, granularity: SelectionGranularity)
pub fn start(&mut self, pos: BufferPos, granularity: SelectionGranularity)
Begin a new selection at pos.
Transitions: None → Selecting, Active → Selecting. Clears any previous selection.
Sourcepub fn start_with_shape(
&mut self,
pos: BufferPos,
granularity: SelectionGranularity,
shape: SelectionShape,
)
pub fn start_with_shape( &mut self, pos: BufferPos, granularity: SelectionGranularity, shape: SelectionShape, )
Begin a new selection with a specific shape.
Sourcepub fn drag(&mut self, pos: BufferPos)
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.
Sourcepub fn drag_expanded(
&mut self,
pos: BufferPos,
grid: &Grid,
scrollback: &Scrollback,
)
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.
Sourcepub fn commit(&mut self)
pub fn commit(&mut self)
Commit the current selection (mouse released).
Transitions: Selecting → Active. No-op if not selecting.
Sourcepub fn toggle_shape(&mut self)
pub fn toggle_shape(&mut self)
Toggle between linear and rectangular selection.
Preserves the current selection range, only changes shape.
Sourcepub fn contains(&self, line: u32, col: u16) -> bool
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).
Sourcepub fn extract_text(
&self,
grid: &Grid,
scrollback: &Scrollback,
) -> Option<String>
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.
Sourcepub fn extract_copy(
&self,
grid: &Grid,
scrollback: &Scrollback,
opts: &CopyOptions,
) -> Option<String>
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
impl Clone for SelectionState
Source§fn clone(&self) -> SelectionState
fn clone(&self) -> SelectionState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more