Skip to main content

SelectionState

Struct SelectionState 

Source
pub struct SelectionState {
    pub active: bool,
    pub anchor: Option<SelectionPos>,
    pub cursor: Option<SelectionPos>,
    pub frozen_lines: Option<Vec<Line<'static>>>,
    pub frozen_width: usize,
    pub last_copied_text: Option<String>,
}
Expand description

Selection state for markdown widget.

Tracks whether selection mode is active and the selection bounds.

Fields§

§active: bool

Whether selection mode is active.

§anchor: Option<SelectionPos>

Selection anchor (start point).

§cursor: Option<SelectionPos>

Current cursor/end position.

§frozen_lines: Option<Vec<Line<'static>>>

Cached rendered lines for stable selection.

§frozen_width: usize

Width when lines were frozen.

§last_copied_text: Option<String>

Last copied text (for showing toast notification).

Implementations§

Source§

impl SelectionState

Constructor for SelectionState.

Source

pub fn new() -> SelectionState

Available on crate feature markdown-preview only.

Create a new inactive selection state.

Source§

impl SelectionState

Source

pub fn enter(&mut self, x: i32, y: i32, lines: Vec<Line<'static>>, width: usize)

Available on crate feature markdown-preview only.

Enter selection mode at the given position.

§Arguments
  • x - X coordinate (column)
  • y - Y coordinate (document row)
  • lines - Current rendered lines to freeze
  • width - Current render width
Source

pub fn is_active(&self) -> bool

Available on crate feature markdown-preview only.

Check if selection mode is active.

Source§

impl SelectionState

Exit selection mode.

Source

pub fn exit(&mut self)

Available on crate feature markdown-preview only.

Exit selection mode and clear state.

Source§

impl SelectionState

Extract selected text from rendered lines.

Source

pub fn get_selected_text(&self) -> Option<String>

Available on crate feature markdown-preview only.

Get the selected text from the frozen lines.

§Returns

The selected text as a string, or None if no selection.

Source§

impl SelectionState

Get the current selection bounds.

Source

pub fn get_selection(&self) -> Option<(SelectionPos, SelectionPos)>

Available on crate feature markdown-preview only.

Get the normalized selection bounds (start, end) where start <= end.

§Returns

Some((start, end)) if there’s an active selection, None otherwise.

Source

pub fn has_selection(&self) -> bool

Available on crate feature markdown-preview only.

Check if there’s an active selection (anchor and cursor set).

Source§

impl SelectionState

Check if a position is within the selection.

Source

pub fn is_in_selection(&self, x: i32, y: i32) -> bool

Available on crate feature markdown-preview only.

Check if a cell at (x, y) is within the current selection.

§Arguments
  • x - X coordinate (column)
  • y - Y coordinate (row)
§Returns

true if the position is within the selection.

Source§

impl SelectionState

Update cursor position during selection.

Source

pub fn update_cursor(&mut self, x: i32, y: i32)

Available on crate feature markdown-preview only.

Update the cursor position during selection.

§Arguments
  • x - New X coordinate
  • y - New Y coordinate
Source

pub fn set_anchor(&mut self)

Available on crate feature markdown-preview only.

Set anchor at current cursor position (for keyboard selection toggle).

Source

pub fn clear_anchor(&mut self)

Available on crate feature markdown-preview only.

Clear anchor (deselect).

Source

pub fn toggle_anchor(&mut self)

Available on crate feature markdown-preview only.

Toggle anchor at current position.

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<(), Error>

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

impl Default for SelectionState

Source§

fn default() -> SelectionState

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more