euv_core/system/text_edit/struct.rs
1use super::*;
2
3/// UTF-8 byte-indexed text selection pairing an anchor offset with the active caret focus offset.
4#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
5pub struct TextSelection {
6 /// Selection anchor offset in UTF-8 bytes.
7 #[get(type(copy))]
8 pub(crate) anchor: usize,
9 /// Active caret focus offset in UTF-8 bytes.
10 #[get(type(copy))]
11 pub(crate) focus: usize,
12}
13
14/// Immutable editor state snapshot stored on the Undo and Redo stacks.
15#[derive(Clone, Data, Debug, Default, Eq, New, PartialEq)]
16pub struct TextEditSnapshot {
17 /// Full UTF-8 buffer contents prior to or following an edit.
18 pub(crate) text: String,
19 /// Caret and selection range associated with `text`.
20 #[get(type(copy))]
21 pub(crate) selection: TextSelection,
22 /// Mutation kind recorded for this snapshot.
23 #[get(type(copy))]
24 pub(crate) edit_kind: TextEditKind,
25 /// Monotonic edit timestamp in milliseconds.
26 #[get(type(copy))]
27 pub(crate) timestamp_ms: u64,
28}
29
30/// Byte-offset underline clause span inside an active IME preedit composition string.
31#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
32pub struct ImeUnderlineSpan {
33 /// Inclusive UTF-8 byte start offset within `ImePreeditState::composition`.
34 #[get(type(copy))]
35 pub(crate) start_byte: usize,
36 /// Exclusive UTF-8 byte end offset within `ImePreeditState::composition`.
37 #[get(type(copy))]
38 pub(crate) end_byte: usize,
39 /// Visual underline decoration style for this clause.
40 #[get(type(copy))]
41 pub(crate) style: ImeUnderlineStyle,
42}
43
44/// Active OS Input Method Editor (IME) preedit composition state for CJK and dead-key input.
45#[derive(Clone, Data, Debug, Default, PartialEq)]
46pub struct ImePreeditState {
47 /// Whether an active OS IME preedit session is currently in progress.
48 #[get(type(copy))]
49 pub(crate) active: bool,
50 /// Uncommitted UTF-8 composition string rendered inline at the caret.
51 pub(crate) composition: String,
52 /// Inclusive UTF-8 byte start of the preedit selection/caret inside `composition`.
53 #[get(type(copy))]
54 pub(crate) cursor_start_byte: usize,
55 /// Exclusive UTF-8 byte end of the preedit selection/caret inside `composition`.
56 #[get(type(copy))]
57 pub(crate) cursor_end_byte: usize,
58 /// Clause underline spans highlighting active vs secondary IME conversion segments.
59 pub(crate) underlines: Vec<ImeUnderlineSpan>,
60 /// Screen-space logical anchor rectangle reported to the OS IME candidate popup window.
61 #[get(type(copy))]
62 pub(crate) candidate_anchor_rect: Rect,
63}
64
65/// Production UTF-8 text editing buffer with coalesced Undo/Redo history, word navigation, selection ops, and IME preedit state.
66#[derive(Clone, Data, Debug)]
67pub struct TextEditHistory {
68 /// Committed UTF-8 text buffer.
69 pub(crate) text: String,
70 /// Active UTF-8 byte selection and caret position.
71 #[get(type(copy))]
72 pub(crate) selection: TextSelection,
73 /// Bounded stack of prior editor snapshots for Undo.
74 #[get(pub(crate))]
75 #[get_mut(pub(crate))]
76 #[set(skip)]
77 pub(crate) undo_stack: VecDeque<TextEditSnapshot>,
78 /// Stack of undone editor snapshots for Redo.
79 #[get(pub(crate))]
80 #[get_mut(pub(crate))]
81 #[set(skip)]
82 pub(crate) redo_stack: Vec<TextEditSnapshot>,
83 /// Maximum number of snapshots retained in `undo_stack`.
84 #[get(type(copy))]
85 pub(crate) max_history: usize,
86 /// Maximum elapsed milliseconds during which consecutive single-step edits coalesce.
87 #[get(type(copy))]
88 pub(crate) coalesce_window_ms: u64,
89 /// Kind of the most recent coalescable edit.
90 #[get(type(copy))]
91 pub(crate) last_edit_kind: TextEditKind,
92 /// Timestamp of the most recent coalescable edit in milliseconds.
93 #[get(type(copy))]
94 pub(crate) last_edit_timestamp_ms: u64,
95 /// Whether the next compatible edit within `coalesce_window_ms` may coalesce with the top Undo entry.
96 #[get(type(copy))]
97 pub(crate) has_coalesce_anchor: bool,
98 /// Live IME preedit composition state attached to this editing buffer.
99 pub(crate) ime_preedit: ImePreeditState,
100}