euv-core 0.52.0

Core cross-platform runtime for euv featuring arena-based fine-grained reactivity, deterministic layout, flat scene graph, multi-mode rendering, and direct OS platform adapters.
Documentation
use super::*;

/// UTF-8 byte-indexed text selection pairing an anchor offset with the active caret focus offset.
#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
pub struct TextSelection {
    /// Selection anchor offset in UTF-8 bytes.
    #[get(type(copy))]
    pub(crate) anchor: usize,
    /// Active caret focus offset in UTF-8 bytes.
    #[get(type(copy))]
    pub(crate) focus: usize,
}

/// Immutable editor state snapshot stored on the Undo and Redo stacks.
#[derive(Clone, Data, Debug, Default, Eq, New, PartialEq)]
pub struct TextEditSnapshot {
    /// Full UTF-8 buffer contents prior to or following an edit.
    pub(crate) text: String,
    /// Caret and selection range associated with `text`.
    #[get(type(copy))]
    pub(crate) selection: TextSelection,
    /// Mutation kind recorded for this snapshot.
    #[get(type(copy))]
    pub(crate) edit_kind: TextEditKind,
    /// Monotonic edit timestamp in milliseconds.
    #[get(type(copy))]
    pub(crate) timestamp_ms: u64,
}

/// Byte-offset underline clause span inside an active IME preedit composition string.
#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
pub struct ImeUnderlineSpan {
    /// Inclusive UTF-8 byte start offset within `ImePreeditState::composition`.
    #[get(type(copy))]
    pub(crate) start_byte: usize,
    /// Exclusive UTF-8 byte end offset within `ImePreeditState::composition`.
    #[get(type(copy))]
    pub(crate) end_byte: usize,
    /// Visual underline decoration style for this clause.
    #[get(type(copy))]
    pub(crate) style: ImeUnderlineStyle,
}

/// Active OS Input Method Editor (IME) preedit composition state for CJK and dead-key input.
#[derive(Clone, Data, Debug, Default, PartialEq)]
pub struct ImePreeditState {
    /// Whether an active OS IME preedit session is currently in progress.
    #[get(type(copy))]
    pub(crate) active: bool,
    /// Uncommitted UTF-8 composition string rendered inline at the caret.
    pub(crate) composition: String,
    /// Inclusive UTF-8 byte start of the preedit selection/caret inside `composition`.
    #[get(type(copy))]
    pub(crate) cursor_start_byte: usize,
    /// Exclusive UTF-8 byte end of the preedit selection/caret inside `composition`.
    #[get(type(copy))]
    pub(crate) cursor_end_byte: usize,
    /// Clause underline spans highlighting active vs secondary IME conversion segments.
    pub(crate) underlines: Vec<ImeUnderlineSpan>,
    /// Screen-space logical anchor rectangle reported to the OS IME candidate popup window.
    #[get(type(copy))]
    pub(crate) candidate_anchor_rect: Rect,
}

/// Production UTF-8 text editing buffer with coalesced Undo/Redo history, word navigation, selection ops, and IME preedit state.
#[derive(Clone, Data, Debug)]
pub struct TextEditHistory {
    /// Committed UTF-8 text buffer.
    pub(crate) text: String,
    /// Active UTF-8 byte selection and caret position.
    #[get(type(copy))]
    pub(crate) selection: TextSelection,
    /// Bounded stack of prior editor snapshots for Undo.
    #[get(pub(crate))]
    #[get_mut(pub(crate))]
    #[set(skip)]
    pub(crate) undo_stack: VecDeque<TextEditSnapshot>,
    /// Stack of undone editor snapshots for Redo.
    #[get(pub(crate))]
    #[get_mut(pub(crate))]
    #[set(skip)]
    pub(crate) redo_stack: Vec<TextEditSnapshot>,
    /// Maximum number of snapshots retained in `undo_stack`.
    #[get(type(copy))]
    pub(crate) max_history: usize,
    /// Maximum elapsed milliseconds during which consecutive single-step edits coalesce.
    #[get(type(copy))]
    pub(crate) coalesce_window_ms: u64,
    /// Kind of the most recent coalescable edit.
    #[get(type(copy))]
    pub(crate) last_edit_kind: TextEditKind,
    /// Timestamp of the most recent coalescable edit in milliseconds.
    #[get(type(copy))]
    pub(crate) last_edit_timestamp_ms: u64,
    /// Whether the next compatible edit within `coalesce_window_ms` may coalesce with the top Undo entry.
    #[get(type(copy))]
    pub(crate) has_coalesce_anchor: bool,
    /// Live IME preedit composition state attached to this editing buffer.
    pub(crate) ime_preedit: ImePreeditState,
}