Skip to main content

TextSelection

Struct TextSelection 

Source
pub struct TextSelection {
    pub dom_id: DomId,
    pub anchor: SelectionAnchor,
    pub focus: SelectionFocus,
    pub affected_nodes: BTreeMap<NodeId, SelectionRange>,
    pub is_forward: bool,
}
Expand description

Complete selection state spanning potentially multiple DOM nodes.

This implements the W3C Selection API model with anchor/focus endpoints. The selection can span multiple IFC roots (e.g., multiple <p> elements).

§Storage Model

Uses BTreeMap<NodeId, SelectionRange> for O(log N) lookup during rendering. The key is the IFC root NodeId, and the value is the SelectionRange for that IFC.

§Example

<p id="1">Hello [World</p>     <- Anchor in IFC 1, partial selection
<p id="2">Complete line</p>    <- InBetween, fully selected
<p id="3">Partial] end</p>     <- Focus in IFC 3, partial selection

Fields§

§dom_id: DomId

The DOM this selection belongs to.

§anchor: SelectionAnchor

The anchor point - where the selection started (fixed during drag).

§focus: SelectionFocus

The focus point - where the selection currently ends (moves during drag).

§affected_nodes: BTreeMap<NodeId, SelectionRange>

Map from IFC root NodeId to the SelectionRange for that IFC. This allows O(log N) lookup during rendering.

The SelectionRange contains the actual TextCursor positions for that IFC, ready to be passed to UnifiedLayout::get_selection_rects().

§is_forward: bool

Indicates whether anchor comes before focus in document order. True = forward selection (left-to-right), False = backward selection.

Implementations§

Source§

impl TextSelection

Source

pub fn new_collapsed( dom_id: DomId, ifc_root_node_id: NodeId, cursor: TextCursor, char_bounds: LogicalRect, mouse_position: LogicalPosition, ) -> Self

Create a new collapsed selection (cursor) at the given position.

Source

pub fn is_collapsed(&self) -> bool

Check if this is a collapsed selection (cursor with no range).

Source

pub fn get_range_for_node( &self, ifc_root_node_id: &NodeId, ) -> Option<&SelectionRange>

Get the selection range for a specific IFC root node. Returns None if this node is not part of the selection.

Source

pub fn contains_node(&self, ifc_root_node_id: &NodeId) -> bool

Check if a specific IFC root node is part of this selection.

Source

pub fn get_node_selection_type( &self, ifc_root_node_id: &NodeId, ) -> Option<NodeSelectionType>

Get the selection type for a specific node.

Trait Implementations§

Source§

impl Clone for TextSelection

Source§

fn clone(&self) -> TextSelection

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 TextSelection

Source§

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

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

impl PartialEq for TextSelection

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for TextSelection

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> 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.