pub struct SelectionManager {
pub selections: BTreeMap<DomId, SelectionState>,
pub text_selections: BTreeMap<DomId, TextSelection>,
pub click_state: ClickState,
}Expand description
Manager for text selections across all DOMs
This manager supports both the legacy per-node selection model and the new browser-style anchor/focus model for multi-node selection.
Fields§
§selections: BTreeMap<DomId, SelectionState>Legacy selection state for each DOM (per-node model) Maps DomId -> SelectionState TODO: Deprecate once multi-node selection is fully implemented
text_selections: BTreeMap<DomId, TextSelection>New multi-node selection state using anchor/focus model Maps DomId -> TextSelection
click_state: ClickStateClick state for multi-click detection
Implementations§
Source§impl SelectionManager
impl SelectionManager
Sourcepub const MULTI_CLICK_TIMEOUT_MS: u64 = 500
pub const MULTI_CLICK_TIMEOUT_MS: u64 = 500
Multi-click timeout in milliseconds
Sourcepub const MULTI_CLICK_DISTANCE_PX: f32 = 5.0
pub const MULTI_CLICK_DISTANCE_PX: f32 = 5.0
Multi-click maximum distance in pixels
Sourcepub fn update_click_count(
&mut self,
node_id: DomNodeId,
position: LogicalPosition,
current_time_ms: u64,
) -> u8
pub fn update_click_count( &mut self, node_id: DomNodeId, position: LogicalPosition, current_time_ms: u64, ) -> u8
Update click count based on position and time Returns the new click count (1=single, 2=double, 3=triple)
Sourcepub fn get_selection(&self, dom_id: &DomId) -> Option<&SelectionState>
pub fn get_selection(&self, dom_id: &DomId) -> Option<&SelectionState>
Get the selection state for a DOM
Sourcepub fn get_selection_mut(
&mut self,
dom_id: &DomId,
) -> Option<&mut SelectionState>
pub fn get_selection_mut( &mut self, dom_id: &DomId, ) -> Option<&mut SelectionState>
Get mutable selection state for a DOM
Sourcepub fn set_selection(&mut self, dom_id: DomId, selection: SelectionState)
pub fn set_selection(&mut self, dom_id: DomId, selection: SelectionState)
Set the selection state for a DOM
Sourcepub fn set_cursor(
&mut self,
dom_id: DomId,
node_id: DomNodeId,
cursor: TextCursor,
)
pub fn set_cursor( &mut self, dom_id: DomId, node_id: DomNodeId, cursor: TextCursor, )
Set a single cursor for a DOM, replacing all existing selections
Sourcepub fn set_range(
&mut self,
dom_id: DomId,
node_id: DomNodeId,
range: SelectionRange,
)
pub fn set_range( &mut self, dom_id: DomId, node_id: DomNodeId, range: SelectionRange, )
Set a selection range for a DOM, replacing all existing selections
Sourcepub fn add_selection(
&mut self,
dom_id: DomId,
node_id: DomNodeId,
selection: Selection,
)
pub fn add_selection( &mut self, dom_id: DomId, node_id: DomNodeId, selection: Selection, )
Add a selection to an existing selection state (for multi-cursor support)
Sourcepub fn clear_selection(&mut self, dom_id: &DomId)
pub fn clear_selection(&mut self, dom_id: &DomId)
Clear the selection for a DOM
Sourcepub fn get_all_selections(&self) -> &BTreeMap<DomId, SelectionState>
pub fn get_all_selections(&self) -> &BTreeMap<DomId, SelectionState>
Get all selections
Sourcepub fn has_any_selection(&self) -> bool
pub fn has_any_selection(&self) -> bool
Check if any DOM has an active selection
Sourcepub fn has_selection(&self, dom_id: &DomId) -> bool
pub fn has_selection(&self, dom_id: &DomId) -> bool
Check if a specific DOM has a selection
Sourcepub fn get_primary_cursor(&self, dom_id: &DomId) -> Option<TextCursor>
pub fn get_primary_cursor(&self, dom_id: &DomId) -> Option<TextCursor>
Get the primary cursor for a DOM (first cursor in selection list)
Sourcepub fn get_ranges(&self, dom_id: &DomId) -> Vec<SelectionRange>
pub fn get_ranges(&self, dom_id: &DomId) -> Vec<SelectionRange>
Get all selection ranges for a DOM (excludes plain cursors)
Sourcepub fn analyze_click_for_selection(
&self,
node_id: DomNodeId,
position: LogicalPosition,
current_time_ms: u64,
) -> Option<u8>
pub fn analyze_click_for_selection( &self, node_id: DomNodeId, position: LogicalPosition, current_time_ms: u64, ) -> Option<u8>
Analyze a click event and return what type of text selection should be performed
This is used by the event system to determine if a click should trigger text selection (single/double/triple click).
§Returns
Some(1)- Single click (place cursor)Some(2)- Double click (select word)Some(3)- Triple click (select paragraph/line)None- Not a text selection click (click count > 3 or timeout/distance exceeded)
Sourcepub fn start_selection(
&mut self,
dom_id: DomId,
ifc_root_node_id: NodeId,
cursor: TextCursor,
char_bounds: LogicalRect,
mouse_position: LogicalPosition,
)
pub fn start_selection( &mut self, dom_id: DomId, ifc_root_node_id: NodeId, cursor: TextCursor, char_bounds: LogicalRect, mouse_position: LogicalPosition, )
Start a new text selection with an anchor point.
This is called on MouseDown. It creates a collapsed selection (cursor) at the anchor position. The focus will be updated during drag.
§Parameters
dom_id- The DOM this selection belongs toifc_root_node_id- The IFC root node where the click occurredcursor- The cursor position within the IFC’s UnifiedLayoutchar_bounds- Visual bounds of the clicked charactermouse_position- Mouse position in viewport coordinates
Sourcepub fn update_selection_focus(
&mut self,
dom_id: &DomId,
ifc_root_node_id: NodeId,
cursor: TextCursor,
mouse_position: LogicalPosition,
affected_nodes: BTreeMap<NodeId, SelectionRange>,
is_forward: bool,
) -> bool
pub fn update_selection_focus( &mut self, dom_id: &DomId, ifc_root_node_id: NodeId, cursor: TextCursor, mouse_position: LogicalPosition, affected_nodes: BTreeMap<NodeId, SelectionRange>, is_forward: bool, ) -> bool
Update the focus point of an ongoing selection.
This is called during MouseMove/Drag. It updates the focus position and recomputes the affected nodes between anchor and focus.
§Parameters
dom_id- The DOM this selection belongs toifc_root_node_id- The IFC root node where the focus is nowcursor- The cursor position within the IFC’s UnifiedLayoutmouse_position- Current mouse position in viewport coordinatesaffected_nodes- Pre-computed map of affected IFC roots to their SelectionRangesis_forward- Whether anchor comes before focus in document order
§Returns
trueif the selection was updatedfalseif no selection exists for this DOM
Sourcepub fn get_text_selection(&self, dom_id: &DomId) -> Option<&TextSelection>
pub fn get_text_selection(&self, dom_id: &DomId) -> Option<&TextSelection>
Get the current text selection for a DOM.
Sourcepub fn get_text_selection_mut(
&mut self,
dom_id: &DomId,
) -> Option<&mut TextSelection>
pub fn get_text_selection_mut( &mut self, dom_id: &DomId, ) -> Option<&mut TextSelection>
Get mutable reference to the current text selection for a DOM.
Sourcepub fn has_text_selection(&self, dom_id: &DomId) -> bool
pub fn has_text_selection(&self, dom_id: &DomId) -> bool
Check if a DOM has an active text selection (new model).
Sourcepub fn get_range_for_ifc_root(
&self,
dom_id: &DomId,
ifc_root_node_id: &NodeId,
) -> Option<&SelectionRange>
pub fn get_range_for_ifc_root( &self, dom_id: &DomId, ifc_root_node_id: &NodeId, ) -> Option<&SelectionRange>
Get the selection range for a specific IFC root node.
This is used by the renderer to quickly look up if a node is selected
and get its selection range for get_selection_rects().
§Parameters
dom_id- The DOM to checkifc_root_node_id- The IFC root node to look up
§Returns
Some(&SelectionRange)if this node is part of the selectionNoneif not selected
Sourcepub fn clear_text_selection(&mut self, dom_id: &DomId)
pub fn clear_text_selection(&mut self, dom_id: &DomId)
Clear the text selection for a DOM (new model).
Sourcepub fn clear_all_text_selections(&mut self)
pub fn clear_all_text_selections(&mut self)
Clear all text selections (new model).
Sourcepub fn get_all_text_selections(&self) -> &BTreeMap<DomId, TextSelection>
pub fn get_all_text_selections(&self) -> &BTreeMap<DomId, TextSelection>
Get all text selections.
Trait Implementations§
Source§impl Clone for SelectionManager
impl Clone for SelectionManager
Source§fn clone(&self) -> SelectionManager
fn clone(&self) -> SelectionManager
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SelectionManager
impl Debug for SelectionManager
Source§impl Default for SelectionManager
impl Default for SelectionManager
Source§impl PartialEq for SelectionManager
impl PartialEq for SelectionManager
Source§impl SelectionManagerQuery for SelectionManager
impl SelectionManagerQuery for SelectionManager
Source§fn get_click_count(&self) -> u8
fn get_click_count(&self) -> u8
Source§fn get_drag_start_position(&self) -> Option<LogicalPosition>
fn get_drag_start_position(&self) -> Option<LogicalPosition>
Source§fn has_selection(&self) -> bool
fn has_selection(&self) -> bool
impl StructuralPartialEq for SelectionManager
Auto Trait Implementations§
impl Freeze for SelectionManager
impl RefUnwindSafe for SelectionManager
impl Send for SelectionManager
impl Sync for SelectionManager
impl Unpin for SelectionManager
impl UnwindSafe for SelectionManager
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