Skip to main content

Module selection

Module selection 

Source
Expand description

Primitives for cursor and text selection handling 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 array
  • GraphemeClusterId: Stable identifier for a grapheme cluster (survives reordering)
  • TextCursor: Precise cursor location with leading/trailing affinity
  • SelectionRange: 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§

ContentIndex
A stable, logical pointer to an item within the original InlineContent array.
GraphemeClusterId
A stable, logical identifier for a grapheme cluster.
SelectionAnchor
The anchor point of a text selection - where the user started selecting.
SelectionFocus
The focus point of a text selection - where the selection currently ends.
SelectionRange
Represents a range of selected text. The direction is implicit (start can be logically after end if selecting backwards).
SelectionRangeVec
SelectionRangeVecSlice
C-compatible slice type for $struct_name. This is a non-owning view into a Vec’s data.
SelectionState
The complete selection state for a single text block, supporting multiple cursors/ranges.
SelectionVec
SelectionVecSlice
C-compatible slice type for $struct_name. This is a non-owning view into a Vec’s data.
TextCursor
Represents a precise cursor location in the logical text.
TextSelection
Complete selection state spanning potentially multiple DOM nodes.

Enums§

CursorAffinity
Represents the logical position of the cursor between two grapheme clusters or at the start/end of the text.
NodeSelectionType
Type of selection for a specific node within a multi-node selection.
OptionSelection
OptionSelectionRange
OptionSelectionState
OptionTextCursor
OptionTextSelection
Selection
A single selection, which can be either a blinking cursor or a highlighted range.
SelectionRangeVecDestructor
SelectionVecDestructor

Type Aliases§

SelectionRangeVecDestructorType
SelectionVecDestructorType