Skip to main content

SelectionManager

Struct SelectionManager 

Source
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: ClickState

Click state for multi-click detection

Implementations§

Source§

impl SelectionManager

Source

pub const MULTI_CLICK_TIMEOUT_MS: u64 = 500

Multi-click timeout in milliseconds

Source

pub const MULTI_CLICK_DISTANCE_PX: f32 = 5.0

Multi-click maximum distance in pixels

Source

pub fn new() -> Self

Create a new selection manager

Source

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)

Source

pub fn get_selection(&self, dom_id: &DomId) -> Option<&SelectionState>

Get the selection state for a DOM

Source

pub fn get_selection_mut( &mut self, dom_id: &DomId, ) -> Option<&mut SelectionState>

Get mutable selection state for a DOM

Source

pub fn set_selection(&mut self, dom_id: DomId, selection: SelectionState)

Set the selection state for a DOM

Source

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

Source

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

Source

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)

Source

pub fn clear_selection(&mut self, dom_id: &DomId)

Clear the selection for a DOM

Source

pub fn clear_all(&mut self)

Clear all selections

Source

pub fn get_all_selections(&self) -> &BTreeMap<DomId, SelectionState>

Get all selections

Source

pub fn has_any_selection(&self) -> bool

Check if any DOM has an active selection

Source

pub fn has_selection(&self, dom_id: &DomId) -> bool

Check if a specific DOM has a selection

Source

pub fn get_primary_cursor(&self, dom_id: &DomId) -> Option<TextCursor>

Get the primary cursor for a DOM (first cursor in selection list)

Source

pub fn get_ranges(&self, dom_id: &DomId) -> Vec<SelectionRange>

Get all selection ranges for a DOM (excludes plain cursors)

Source

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)
Source

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 to
  • ifc_root_node_id - The IFC root node where the click occurred
  • cursor - The cursor position within the IFC’s UnifiedLayout
  • char_bounds - Visual bounds of the clicked character
  • mouse_position - Mouse position in viewport coordinates
Source

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 to
  • ifc_root_node_id - The IFC root node where the focus is now
  • cursor - The cursor position within the IFC’s UnifiedLayout
  • mouse_position - Current mouse position in viewport coordinates
  • affected_nodes - Pre-computed map of affected IFC roots to their SelectionRanges
  • is_forward - Whether anchor comes before focus in document order
§Returns
  • true if the selection was updated
  • false if no selection exists for this DOM
Source

pub fn get_text_selection(&self, dom_id: &DomId) -> Option<&TextSelection>

Get the current text selection for a DOM.

Source

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.

Source

pub fn has_text_selection(&self, dom_id: &DomId) -> bool

Check if a DOM has an active text selection (new model).

Source

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 check
  • ifc_root_node_id - The IFC root node to look up
§Returns
  • Some(&SelectionRange) if this node is part of the selection
  • None if not selected
Source

pub fn clear_text_selection(&mut self, dom_id: &DomId)

Clear the text selection for a DOM (new model).

Source

pub fn clear_all_text_selections(&mut self)

Clear all text selections (new model).

Source

pub fn get_all_text_selections(&self) -> &BTreeMap<DomId, TextSelection>

Get all text selections.

Source§

impl SelectionManager

Source

pub fn remap_node_ids( &mut self, dom_id: DomId, node_id_map: &BTreeMap<NodeId, NodeId>, )

Remap NodeIds after DOM reconciliation

When the DOM is regenerated, NodeIds can change. This method updates all internal state to use the new NodeIds based on the provided mapping.

Trait Implementations§

Source§

impl Clone for SelectionManager

Source§

fn clone(&self) -> SelectionManager

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 SelectionManager

Source§

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

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

impl Default for SelectionManager

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for SelectionManager

Source§

fn eq(&self, other: &SelectionManager) -> 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 SelectionManagerQuery for SelectionManager

Source§

fn get_click_count(&self) -> u8

Get the current click count (1 = single, 2 = double, 3 = triple)
Source§

fn get_drag_start_position(&self) -> Option<LogicalPosition>

Get the drag start position if a drag is in progress
Source§

fn has_selection(&self) -> bool

Check if any selection exists (click selection or drag selection)
Source§

impl StructuralPartialEq for SelectionManager

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.
Source§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

Source§

fn is_within(&self, b: &G2) -> bool