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 selectionFields§
§dom_id: DomIdThe DOM this selection belongs to.
anchor: SelectionAnchorThe anchor point - where the selection started (fixed during drag).
focus: SelectionFocusThe 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: boolIndicates whether anchor comes before focus in document order. True = forward selection (left-to-right), False = backward selection.
Implementations§
Source§impl TextSelection
impl TextSelection
Sourcepub fn new_collapsed(
dom_id: DomId,
ifc_root_node_id: NodeId,
cursor: TextCursor,
char_bounds: LogicalRect,
mouse_position: LogicalPosition,
) -> Self
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.
Sourcepub fn is_collapsed(&self) -> bool
pub fn is_collapsed(&self) -> bool
Check if this is a collapsed selection (cursor with no range).
Sourcepub fn get_range_for_node(
&self,
ifc_root_node_id: &NodeId,
) -> Option<&SelectionRange>
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.
Sourcepub fn contains_node(&self, ifc_root_node_id: &NodeId) -> bool
pub fn contains_node(&self, ifc_root_node_id: &NodeId) -> bool
Check if a specific IFC root node is part of this selection.
Sourcepub fn get_node_selection_type(
&self,
ifc_root_node_id: &NodeId,
) -> Option<NodeSelectionType>
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
impl Clone for TextSelection
Source§fn clone(&self) -> TextSelection
fn clone(&self) -> TextSelection
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TextSelection
impl Debug for TextSelection
Source§impl PartialEq for TextSelection
impl PartialEq for TextSelection
impl StructuralPartialEq for TextSelection
Auto Trait Implementations§
impl Freeze for TextSelection
impl RefUnwindSafe for TextSelection
impl Send for TextSelection
impl Sync for TextSelection
impl Unpin for TextSelection
impl UnwindSafe for TextSelection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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