Skip to main content

CursorManager

Struct CursorManager 

Source
pub struct CursorManager {
    pub cursor: Option<TextCursor>,
    pub cursor_location: Option<CursorLocation>,
    pub is_visible: bool,
    pub last_input_time: Option<Instant>,
    pub blink_timer_active: bool,
}
Expand description

Manager for text cursor position and rendering

Fields§

§cursor: Option<TextCursor>

Current cursor position (if any)

§cursor_location: Option<CursorLocation>

DOM and node where the cursor is located

§is_visible: bool

Whether the cursor is currently visible (toggled by blink timer)

§last_input_time: Option<Instant>

Timestamp of the last user input event (keyboard, mouse click in text) Used to determine whether to blink or stay solid while typing

§blink_timer_active: bool

Whether the cursor blink timer is currently active

Implementations§

Source§

impl CursorManager

Source

pub fn new() -> Self

Create a new cursor manager with no cursor

Source

pub fn get_cursor(&self) -> Option<&TextCursor>

Get the current cursor position

Source

pub fn get_cursor_location(&self) -> Option<&CursorLocation>

Get the current cursor location

Source

pub fn set_cursor( &mut self, cursor: Option<TextCursor>, location: Option<CursorLocation>, )

Set the cursor position manually

This is used for programmatic cursor positioning. For automatic initialization when focusing a contenteditable element, use initialize_cursor_at_end().

Source

pub fn set_cursor_with_time( &mut self, cursor: Option<TextCursor>, location: Option<CursorLocation>, now: Instant, )

Set the cursor position with timestamp for blink reset

Source

pub fn clear(&mut self)

Clear the cursor

This is automatically called when focus moves to a non-editable node or when focus is cleared entirely.

Source

pub fn has_cursor(&self) -> bool

Check if there is an active cursor

Source

pub fn should_draw_cursor(&self) -> bool

Check if the cursor should be drawn (has cursor AND is visible)

Reset the blink state on user input

This makes the cursor visible and records the input time. The blink timer will keep the cursor visible until CURSOR_BLINK_INTERVAL_MS has passed since this time.

Source

pub fn toggle_visibility(&mut self) -> bool

Toggle cursor visibility (called by blink timer)

Returns the new visibility state.

Source

pub fn set_visibility(&mut self, visible: bool)

Set cursor visibility directly

Check if enough time has passed since last input to start blinking

Returns true if the cursor should blink (toggle visibility), false if it should stay solid (user is actively typing).

Mark the blink timer as active

Check if the blink timer is active

Source

pub fn initialize_cursor_at_end( &mut self, dom_id: DomId, node_id: NodeId, text_layout: Option<&Arc<UnifiedLayout>>, ) -> bool

Initialize cursor at the end of the text in the given node

This is called automatically when focus lands on a contenteditable element. It queries the text layout to find the position of the last grapheme cluster and places the cursor there.

§Returns

true if cursor was successfully initialized, false if the node has no text or text layout is not available.

Source

pub fn initialize_cursor_at_start(&mut self, dom_id: DomId, node_id: NodeId)

Initialize cursor at the start of the text in the given node

This can be used for specific navigation scenarios (e.g., Ctrl+Home).

Source

pub fn move_cursor_to( &mut self, cursor: TextCursor, dom_id: DomId, node_id: NodeId, )

Move the cursor to a specific position

This is used by text editing operations and keyboard navigation.

Source

pub fn is_cursor_in_node(&self, dom_id: DomId, node_id: NodeId) -> bool

Check if the cursor is in a specific node

Source

pub fn get_cursor_node(&self) -> Option<DomNodeId>

Get the DomNodeId where the cursor is located (for cross-frame tracking)

Source

pub fn update_node_id(&mut self, new_node: DomNodeId)

Update the NodeId for the cursor location (after DOM reconciliation)

This is called when the DOM is regenerated and NodeIds change. The cursor position within the text is preserved.

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 the cursor location to use the new NodeId based on the provided mapping.

Trait Implementations§

Source§

impl Clone for CursorManager

Source§

fn clone(&self) -> CursorManager

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 CursorManager

Source§

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

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

impl Default for CursorManager

Source§

fn default() -> Self

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

impl PartialEq for CursorManager

Source§

fn eq(&self, other: &Self) -> 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.

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