pub struct MultiCursorState {
pub selections: Vec<IdentifiedSelection>,
pub node_id: DomNodeId,
pub contenteditable_key: u64,
}Expand description
Multi-cursor state for a contenteditable element (Sublime Text style).
Replaces the split CursorManager + SelectionManager pattern for text editing. Supports multiple simultaneous cursors/selections, each with a stable ID.
§Invariants
selectionsis sorted by position and non-overlapping.- The primary selection is the last one added (highest index).
- After any mutation,
merge_overlapping()is called to maintain invariants.
Fields§
§selections: Vec<IdentifiedSelection>Sorted by position, non-overlapping. Primary = last added (highest index).
node_id: DomNodeIdThe DOM node this multi-cursor state applies to.
contenteditable_key: u64Stable key that survives DOM rebuilds (from calculate_contenteditable_key).
Implementations§
Source§impl MultiCursorState
impl MultiCursorState
Sourcepub fn new_with_cursor(
cursor: TextCursor,
node_id: DomNodeId,
contenteditable_key: u64,
) -> Self
pub fn new_with_cursor( cursor: TextCursor, node_id: DomNodeId, contenteditable_key: u64, ) -> Self
Create a new MultiCursorState with a single cursor.
Sourcepub fn add_cursor(&mut self, cursor: TextCursor) -> SelectionId
pub fn add_cursor(&mut self, cursor: TextCursor) -> SelectionId
Add a cursor, merging if it overlaps with existing selections. Returns the SelectionId of the new (or merged) cursor.
Sourcepub fn add_selection(&mut self, range: SelectionRange) -> SelectionId
pub fn add_selection(&mut self, range: SelectionRange) -> SelectionId
Add a selection range, merging if it overlaps. Returns the SelectionId of the new (or merged) selection.
Sourcepub fn remove_selection(&mut self, id: SelectionId) -> bool
pub fn remove_selection(&mut self, id: SelectionId) -> bool
Remove a selection by its stable ID. Returns true if found and removed.
Sourcepub fn get_primary(&self) -> Option<&IdentifiedSelection>
pub fn get_primary(&self) -> Option<&IdentifiedSelection>
Get the primary selection (last added = highest index).
Sourcepub fn get_primary_mut(&mut self) -> Option<&mut IdentifiedSelection>
pub fn get_primary_mut(&mut self) -> Option<&mut IdentifiedSelection>
Get a mutable reference to the primary selection.
Sourcepub fn get_primary_cursor(&self) -> Option<TextCursor>
pub fn get_primary_cursor(&self) -> Option<TextCursor>
Get the primary cursor position (for scroll-into-view, IME, etc.)
Sourcepub fn to_selections(&self) -> Vec<Selection>
pub fn to_selections(&self) -> Vec<Selection>
Convert to a Vecedit_text().
Sourcepub fn update_from_edit_result(&mut self, new_selections: &[Selection])
pub fn update_from_edit_result(&mut self, new_selections: &[Selection])
Update selections from the result of edit_text().
Preserves existing IDs where possible (by index), assigns new IDs for extras.
Sourcepub fn set_single_cursor(&mut self, cursor: TextCursor)
pub fn set_single_cursor(&mut self, cursor: TextCursor)
Set all selections to a single cursor (e.g., on plain click without Ctrl).
Sourcepub fn set_single_range(&mut self, range: SelectionRange)
pub fn set_single_range(&mut self, range: SelectionRange)
Set all selections to a single range.
Sourcepub fn merge_overlapping(&mut self)
pub fn merge_overlapping(&mut self)
Sort selections by position and merge any that overlap.
Sourcepub fn move_all_cursors(
&mut self,
extend_selection: bool,
move_fn: impl Fn(&TextCursor) -> TextCursor,
)
pub fn move_all_cursors( &mut self, extend_selection: bool, move_fn: impl Fn(&TextCursor) -> TextCursor, )
Move all cursors using a movement function. Merges collisions afterward.
move_fn takes a TextCursor and returns the new TextCursor after movement.
If extend_selection is true, the anchor stays and only the focus moves,
creating or extending a range.
Trait Implementations§
Source§impl Clone for MultiCursorState
impl Clone for MultiCursorState
Source§fn clone(&self) -> MultiCursorState
fn clone(&self) -> MultiCursorState
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 MultiCursorState
impl Debug for MultiCursorState
Source§impl PartialEq for MultiCursorState
impl PartialEq for MultiCursorState
Source§fn eq(&self, other: &MultiCursorState) -> bool
fn eq(&self, other: &MultiCursorState) -> bool
self and other values to be equal, and is used by ==.