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.
Trait Implementations§
Source§impl Clone for TextSelection
impl Clone for TextSelection
Source§fn clone(&self) -> TextSelection
fn clone(&self) -> TextSelection
1.0.0 (const: unstable) · 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
Source§fn eq(&self, other: &TextSelection) -> bool
fn eq(&self, other: &TextSelection) -> bool
self and other values to be equal, and is used by ==.