ass_editor/events/event.rs
1//! `DocumentEvent` enum describing editor changes.
2//!
3//! Defines the event variants emitted when a document mutates, covering text
4//! edits, cursor/selection updates, lifecycle transitions, and custom events.
5
6use crate::core::{Position, Range};
7
8#[cfg(feature = "std")]
9use std::collections::HashMap;
10
11#[cfg(not(feature = "std"))]
12use alloc::collections::BTreeMap as HashMap;
13
14#[cfg(not(feature = "std"))]
15use alloc::string::String;
16
17/// Types of events that can occur in the editor
18#[derive(Debug, Clone, PartialEq, Eq)]
19pub enum DocumentEvent {
20 /// Text was inserted at a position
21 TextInserted {
22 /// Position where text was inserted
23 position: Position,
24 /// Text that was inserted
25 text: String,
26 /// Length of inserted text in bytes
27 length: usize,
28 },
29
30 /// Text was deleted from a range
31 TextDeleted {
32 /// Range where text was deleted
33 range: Range,
34 /// Text that was deleted (for undo purposes)
35 deleted_text: String,
36 },
37
38 /// Text was replaced in a range
39 TextReplaced {
40 /// Range where text was replaced
41 range: Range,
42 /// Old text that was replaced
43 old_text: String,
44 /// New text that replaced the old text
45 new_text: String,
46 },
47
48 /// Selection changed
49 SelectionChanged {
50 /// Previous selection range (if any)
51 old_selection: Option<Range>,
52 /// New selection range (if any)
53 new_selection: Option<Range>,
54 },
55
56 /// Cursor position changed
57 CursorMoved {
58 /// Previous cursor position
59 old_position: Position,
60 /// New cursor position
61 new_position: Position,
62 },
63
64 /// Document was saved to a file
65 DocumentSaved {
66 /// File path where document was saved
67 file_path: String,
68 /// Whether this was a "save as" operation
69 save_as: bool,
70 },
71
72 /// Document was loaded from a file
73 DocumentLoaded {
74 /// File path from which document was loaded
75 file_path: String,
76 /// Size of loaded document in bytes
77 size: usize,
78 },
79
80 /// Undo operation was performed
81 UndoPerformed {
82 /// Description of the undone action
83 action_description: String,
84 /// Number of changes undone
85 changes_count: usize,
86 },
87
88 /// Redo operation was performed
89 RedoPerformed {
90 /// Description of the redone action
91 action_description: String,
92 /// Number of changes redone
93 changes_count: usize,
94 },
95
96 /// Validation completed with results
97 ValidationCompleted {
98 /// Number of issues found
99 issues_count: usize,
100 /// Number of errors found
101 error_count: usize,
102 /// Number of warnings found
103 warning_count: usize,
104 /// Time taken for validation in milliseconds
105 validation_time_ms: u64,
106 },
107
108 /// Search operation completed
109 SearchCompleted {
110 /// Search pattern that was used
111 pattern: String,
112 /// Number of matches found
113 matches_count: usize,
114 /// Whether the search hit the result limit
115 hit_limit: bool,
116 /// Time taken for search in microseconds
117 search_time_us: u64,
118 },
119
120 /// Document parsing completed
121 ParsingCompleted {
122 /// Whether parsing was successful
123 success: bool,
124 /// Number of sections parsed
125 sections_count: usize,
126 /// Time taken for parsing in milliseconds
127 parse_time_ms: u64,
128 /// Any error message if parsing failed
129 error_message: Option<String>,
130 },
131
132 /// Extension was loaded or unloaded
133 ExtensionChanged {
134 /// Name of the extension
135 extension_name: String,
136 /// Whether the extension was loaded (true) or unloaded (false)
137 loaded: bool,
138 },
139
140 /// Configuration setting changed
141 ConfigChanged {
142 /// Name of the configuration key
143 key: String,
144 /// Old value (if any)
145 old_value: Option<String>,
146 /// New value
147 new_value: String,
148 },
149
150 /// Generic custom event for extensions
151 CustomEvent {
152 /// Event type identifier
153 event_type: String,
154 /// Event data as key-value pairs
155 data: HashMap<String, String>,
156 },
157}