pub struct TextSelection {
pub dom_id: DomId,
pub anchor: SelectionAnchor,
pub focus: SelectionFocus,
pub affected_nodes: BTreeMap<NodeId, Vec<SelectionRange>>,
pub remote_ranges: BTreeMap<NodeId, Vec<(SelectionOwner, 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, Vec<SelectionRange>> for O(log N) lookup during rendering.
The key is the IFC root NodeId, and the value is every SelectionRange
that IFC contributes.
§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, Vec<SelectionRange>>Map from IFC root NodeId to the SelectionRanges for that IFC.
This allows O(log N) lookup during rendering.
Each SelectionRange contains the actual TextCursor positions for that IFC,
ready to be passed to UnifiedLayout::get_selection_rects().
A node carries SEVERAL ranges when a multi-cursor session selects several occurrences in it (Ctrl+D); the ranges are disjoint and in document order.
remote_ranges: BTreeMap<NodeId, Vec<(SelectionOwner, SelectionRange)>>OTHER PARTICIPANTS’ ranges on the same nodes, with whose they are (U1-a).
Separate from affected_nodes rather than mixed into it, because the
two are painted differently and mean different things: that one is the
LOCAL user’s selection and takes the node’s ::selection colour, while
these take their owner’s. Mixing them made a remote participant’s range
look like the local user’s own, which is worse than not showing it.
Empty for a single-user app, which is every app until one injects a remote owner.
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 FIRST selection range for a specific IFC root node.
Returns None if this node is not part of the selection.
A multi-range node has more; Self::ranges_for_node returns all of them.
Sourcepub fn ranges_for_node(&self, ifc_root_node_id: &NodeId) -> &[SelectionRange]
pub fn ranges_for_node(&self, ifc_root_node_id: &NodeId) -> &[SelectionRange]
Every range this IFC root contributes (empty slice when unaffected).
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 more