Skip to main content

SelectionState

Struct SelectionState 

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

Active single-node or cross-node character-range text selection targeting live selectable NodeKind::Text nodes.

Implementations§

Source§

impl SelectionState

Character-range queries and text extraction helpers for SelectionState.

Source

pub const fn single( node_id: NodeId, anchor_char: usize, focus_char: usize, ) -> Self

Constructs a single-node character-range selection on node_id.

§Arguments
  • NodeId - Target NodeKind::Text node handle.
  • usize - Anchor character index.
  • usize - Focus character index.
§Returns
  • Self - Single-node selection state.
Source

pub const fn get_node_id(&self) -> NodeId

Returns the anchor NodeId (matching the single selected node when is_single_node() holds).

§Arguments
  • &Self - Selection state reference.
§Returns
  • NodeId - Anchor text node handle.
Source

pub fn is_single_node(&self) -> bool

Returns true when both endpoints of the selection reside on the same NodeId.

§Arguments
  • &Self - Selection state reference.
§Returns
  • bool - Whether anchor_node == focus_node.
Source

pub const fn ordered_range(&self) -> (usize, usize)

Returns the normalized (start_char, end_char) range with start_char <= end_char for single-node selections.

§Arguments
  • &Self - Selection state reference.
§Returns
  • (usize, usize) - Ordered character index bounds.
Source

pub fn is_empty(&self) -> bool

Returns true when the selection is collapsed (same node and equal character offset).

§Arguments
  • &Self - Selection state reference.
§Returns
  • bool - Whether anchor_node == focus_node && anchor_char == focus_char.
Source

pub fn extract_from<'a>(&self, text: &'a str) -> &'a str

Extracts the selected UTF-8 slice from text for a single-node selection, safely clamping to valid character boundaries.

§Arguments
  • &Self - Selection state reference.
  • &'a str - Source UTF-8 text string of the selected node.
§Returns
  • &'a str - Selected substring slice (empty when collapsed).
Source§

impl SelectionState

Source

pub fn get_anchor_node(&self) -> NodeId

Source

pub fn get_mut_anchor_node(&mut self) -> &mut NodeId

Source

pub fn set_anchor_node(&mut self, val: NodeId) -> &mut Self

Source

pub fn get_anchor_char(&self) -> usize

Source

pub fn get_mut_anchor_char(&mut self) -> &mut usize

Source

pub fn set_anchor_char(&mut self, val: usize) -> &mut Self

Source

pub fn get_focus_node(&self) -> NodeId

Source

pub fn get_mut_focus_node(&mut self) -> &mut NodeId

Source

pub fn set_focus_node(&mut self, val: NodeId) -> &mut Self

Source

pub fn get_focus_char(&self) -> usize

Source

pub fn get_mut_focus_char(&mut self) -> &mut usize

Source

pub fn set_focus_char(&mut self, val: usize) -> &mut Self

Source§

impl SelectionState

Source

pub fn new( anchor_node: NodeId, anchor_char: usize, focus_node: NodeId, focus_char: usize, ) -> Self

Trait Implementations§

Source§

impl Clone for SelectionState

Source§

fn clone(&self) -> Self

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 Copy for SelectionState

Source§

impl Debug for SelectionState

Source§

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

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

impl Eq for SelectionState

Source§

impl PartialEq for SelectionState

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for SelectionState

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.