Expand description
Text selection and cursor positioning for inline content. Text selection and cursor positioning for inline content.
This module provides data structures for managing text cursors and selection ranges in a bidirectional (Bidi) and line-breaking aware manner. It handles:
- Grapheme cluster identification: Unicode-aware character boundaries
- Bidi support: Cursor movement in mixed LTR/RTL text
- Stable positions: Selection anchors survive layout changes
- Affinity tracking: Cursor position at leading/trailing edges
- Multi-node selection: Browser-style selection spanning multiple DOM nodes
§Architecture
Text positions are represented as:
ContentIndex: Logical position in the original inline content arrayGraphemeClusterId: Stable identifier for a grapheme cluster (survives reordering)TextCursor: Precise cursor location with leading/trailing affinitySelectionRange: Start and end cursors defining a selection
Multi-node selection uses an Anchor/Focus model (W3C Selection API):
SelectionAnchor: Fixed point where user started selection (mousedown)SelectionFocus: Movable point where selection currently ends (drag position)TextSelection: Complete selection state spanning potentially multiple IFC roots
§Use Cases
- Text editing: Insert/delete at cursor position
- Selection rendering: Highlight selected text across multiple nodes
- Keyboard navigation: Move cursor by grapheme/word/line
- Mouse selection: Convert pixel coordinates to text positions
- Drag selection: Extend selection across multiple DOM nodes
§Examples
use azul_core::selection::{CursorAffinity, GraphemeClusterId, TextCursor};
let cursor = TextCursor {
cluster_id: GraphemeClusterId {
source_run: 0,
start_byte_in_run: 0,
},
affinity: CursorAffinity::Leading,
};Structs§
- Content
Index - A stable, logical pointer to an item within the original
InlineContentarray. - Grapheme
Cluster Id - A stable, logical identifier for a grapheme cluster.
- Identified
Selection - A selection (cursor or range) paired with a stable identity.
- Identified
Selection Vec - Identified
Selection VecSlice - C-compatible slice type for
$struct_name. This is a non-owning view into a Vec’s data. - Multi
Cursor State - Multi-cursor state for a contenteditable element (Sublime Text style).
- Selection
Anchor - The anchor point of a text selection - where the user started selecting.
- Selection
Focus - The focus point of a text selection - where the selection currently ends.
- Selection
Id - Stable identifier for a cursor/selection within a
MultiCursorState. - Selection
IdVec - Selection
IdVec Slice - C-compatible slice type for
$struct_name. This is a non-owning view into a Vec’s data. - Selection
Range - Represents a range of selected text. The direction is implicit (start can be logically after end if selecting backwards).
- Selection
Range Vec - Selection
Range VecSlice - C-compatible slice type for
$struct_name. This is a non-owning view into a Vec’s data. - Selection
State - The complete selection state for a single text block, supporting multiple cursors/ranges.
- Selection
Vec - Selection
VecSlice - C-compatible slice type for
$struct_name. This is a non-owning view into a Vec’s data. - Text
Cursor - Represents a precise cursor location in the logical text.
- Text
Selection - Complete selection state spanning potentially multiple DOM nodes.
Enums§
- Cursor
Affinity - Represents the logical position of the cursor between two grapheme clusters or at the start/end of the text.
- Identified
Selection VecDestructor - Option
Identified Selection - Option
Selection - Option
Selection Id - Option
Selection Range - Option
Selection State - Option
Text Cursor - Option
Text Selection - Selection
- A single selection, which can be either a blinking cursor or a highlighted range.
- Selection
IdVec Destructor - Selection
Range VecDestructor - Selection
VecDestructor