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: boolWhether 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: boolWhether the cursor blink timer is currently active
Implementations§
Source§impl CursorManager
impl CursorManager
Sourcepub fn get_cursor(&self) -> Option<&TextCursor>
pub fn get_cursor(&self) -> Option<&TextCursor>
Get the current cursor position
Sourcepub fn get_cursor_location(&self) -> Option<&CursorLocation>
pub fn get_cursor_location(&self) -> Option<&CursorLocation>
Get the current cursor location
Sourcepub fn set_cursor(
&mut self,
cursor: Option<TextCursor>,
location: Option<CursorLocation>,
)
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().
Sourcepub fn set_cursor_with_time(
&mut self,
cursor: Option<TextCursor>,
location: Option<CursorLocation>,
now: Instant,
)
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
Sourcepub fn clear(&mut self)
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.
Sourcepub fn has_cursor(&self) -> bool
pub fn has_cursor(&self) -> bool
Check if there is an active cursor
Sourcepub fn should_draw_cursor(&self) -> bool
pub fn should_draw_cursor(&self) -> bool
Check if the cursor should be drawn (has cursor AND is visible)
Sourcepub fn reset_blink_on_input(&mut self, now: Instant)
pub fn reset_blink_on_input(&mut self, now: Instant)
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.
Sourcepub fn toggle_visibility(&mut self) -> bool
pub fn toggle_visibility(&mut self) -> bool
Toggle cursor visibility (called by blink timer)
Returns the new visibility state.
Sourcepub fn set_visibility(&mut self, visible: bool)
pub fn set_visibility(&mut self, visible: bool)
Set cursor visibility directly
Sourcepub fn should_blink(&self, now: &Instant) -> bool
pub fn should_blink(&self, now: &Instant) -> bool
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).
Sourcepub fn set_blink_timer_active(&mut self, active: bool)
pub fn set_blink_timer_active(&mut self, active: bool)
Mark the blink timer as active
Sourcepub fn is_blink_timer_active(&self) -> bool
pub fn is_blink_timer_active(&self) -> bool
Check if the blink timer is active
Sourcepub fn initialize_cursor_at_end(
&mut self,
dom_id: DomId,
node_id: NodeId,
text_layout: Option<&Arc<UnifiedLayout>>,
) -> bool
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.
Sourcepub fn initialize_cursor_at_start(&mut self, dom_id: DomId, node_id: NodeId)
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).
Sourcepub fn move_cursor_to(
&mut self,
cursor: TextCursor,
dom_id: DomId,
node_id: NodeId,
)
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.
Sourcepub fn is_cursor_in_node(&self, dom_id: DomId, node_id: NodeId) -> bool
pub fn is_cursor_in_node(&self, dom_id: DomId, node_id: NodeId) -> bool
Check if the cursor is in a specific node
Sourcepub fn get_cursor_node(&self) -> Option<DomNodeId>
pub fn get_cursor_node(&self) -> Option<DomNodeId>
Get the DomNodeId where the cursor is located (for cross-frame tracking)
Sourcepub fn update_node_id(&mut self, new_node: DomNodeId)
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.
Trait Implementations§
Source§impl Clone for CursorManager
impl Clone for CursorManager
Source§fn clone(&self) -> CursorManager
fn clone(&self) -> CursorManager
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CursorManager
impl Debug for CursorManager
Source§impl Default for CursorManager
impl Default for CursorManager
Source§impl PartialEq for CursorManager
impl PartialEq for CursorManager
Auto Trait Implementations§
impl Freeze for CursorManager
impl RefUnwindSafe for CursorManager
impl Send for CursorManager
impl Sync for CursorManager
impl Unpin for CursorManager
impl UnwindSafe for CursorManager
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