Expand description
Text cursor management
Manages text cursor position and state for contenteditable elements.
§Cursor Lifecycle
The cursor is automatically managed in response to focus changes:
- Focus lands on contenteditable node: Cursor initialized at end of text
- Focus moves to non-editable node: Cursor automatically cleared
- Focus clears entirely: Cursor automatically cleared
§Automatic Cursor Initialization
When focus is set to a contenteditable node via FocusManager::set_focused_node(),
the event system (in window.rs) checks if the node is contenteditable and calls
CursorManager::initialize_cursor_at_end() to place the cursor at the end of the text.
This happens for:
- User clicks on contenteditable element
- Tab navigation to contenteditable element
- Programmatic focus via
AccessibilityAction::Focus - Focus from screen reader commands
§Cursor Blinking
The cursor blinks at ~530ms intervals when a contenteditable element has focus.
Blinking is managed by a system timer (CURSOR_BLINK_TIMER_ID) that:
- Starts when focus lands on a contenteditable element
- Stops when focus moves away
- Resets (cursor becomes visible) on any user input (keyboard, mouse)
- After ~530ms of no input, the cursor toggles visibility
§Integration with Text Layout
The cursor manager uses the TextLayoutCache to determine:
- Total number of grapheme clusters in the text
- Position of the last grapheme cluster (for cursor-at-end)
- Bounding rectangles for scroll-into-view
§Scroll-Into-View
When a cursor is set, the system automatically checks if it’s visible in the
viewport. If not, it uses the ScrollManager to scroll the minimum amount
needed to bring the cursor into view.
§Multi-Cursor Support
While the core TextCursor type supports multi-cursor editing (used in
text3::edit), the CursorManager currently manages a single cursor for
accessibility and user interaction. Multi-cursor scenarios are handled at
the SelectionManager level with multiple Selection::Cursor items.
Structs§
- Cursor
Location - Location of a cursor within the DOM
- Cursor
Manager - Manager for text cursor position and rendering
Constants§
- CURSOR_
BLINK_ INTERVAL_ MS - Default cursor blink interval in milliseconds