1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
//! Editor Core - Industrial-Grade Headless Code Editor Kernel
//!
//! # Overview
//!
//! `editor-core` is a headless code editor kernel focused on state management, text metrics, and
//! coordinate transformations.
//!
//! It does not render UI. Hosts render from snapshots (e.g. [`HeadlessGrid`]) and drive edits via
//! the command/state APIs.
//!
//! # Core Features
//!
//! - **Efficient Text Storage**: Rope-backed text buffer with `char`-indexed access
//! - **Fast Line Index**: Rope-based line access and coordinate conversion
//! - **Soft Wrapping Support**: Headless layout engine, supporting arbitrary container widths
//! - **Style Management**: Interval tree structure, O(log n + k) query complexity
//! - **Code Folding**: Supports arbitrary levels of code folding
//! - **State Tracking**: Version number mechanism and Change Notifications system
//! - **Workspace model**: Multi-buffer + multi-view orchestration (`Workspace`, `BufferId`,
//! `ViewId`) for tabs and split panes
//!
//! # Architecture Layers
//!
//! ```text
//! ┌─────────────────────────────────────────────┐
//! │ Command Interface & State Management │ ← Public API
//! ├─────────────────────────────────────────────┤
//! │ Snapshot API (HeadlessGrid) │ ← Rendering Data
//! ├─────────────────────────────────────────────┤
//! │ Intervals & Visibility (Styles + Folding) │ ← Visual Enhancement
//! ├─────────────────────────────────────────────┤
//! │ Layout Engine (Soft Wrapping) │ ← Text Layout
//! ├─────────────────────────────────────────────┤
//! │ Line Index + TextBuffer (Rope-based) │ ← Text Storage / Line Access
//! └─────────────────────────────────────────────┘
//! ```
//!
//! # Quick Start
//!
//! ## Using Command Interface
//!
//! ```rust
//! use editor_core::{CommandExecutor, Command, EditCommand, CursorCommand, Position};
//!
//! let mut executor = CommandExecutor::empty(80);
//!
//! // Insert text
//! executor.execute(Command::Edit(EditCommand::Insert {
//! offset: 0,
//! text: "fn main() {\n println!(\"Hello\");\n}\n".to_string(),
//! })).unwrap();
//!
//! // Move cursor
//! executor.execute(Command::Cursor(CursorCommand::MoveTo {
//! line: 1,
//! column: 4,
//! })).unwrap();
//!
//! assert_eq!(executor.editor().cursor_position(), Position::new(1, 4));
//! ```
//!
//! ## Using State Management
//!
//! ```rust
//! use editor_core::{EditorStateManager, StateChangeType};
//!
//! let mut manager = EditorStateManager::new("Initial text", 80);
//!
//! // Subscribe to state changes
//! manager.subscribe(|change| {
//! println!("State changed: {:?}", change.change_type);
//! });
//!
//! // Query state
//! let doc_state = manager.get_document_state();
//! println!("Line count: {}, Characters: {}", doc_state.line_count, doc_state.char_count);
//! ```
//!
//! ## Using Workspace (multi-buffer / multi-view)
//!
//! ```rust
//! use editor_core::{Command, CursorCommand, EditCommand, Workspace};
//!
//! let mut ws = Workspace::new();
//! let opened = ws
//! .open_buffer(Some("file:///demo.txt".to_string()), "Hello\nWorld\n", 80)
//! .unwrap();
//!
//! // Commands always target a view.
//! let view = opened.view_id;
//! ws.execute(view, Command::Cursor(CursorCommand::MoveTo { line: 1, column: 0 }))
//! .unwrap();
//! ws.execute(view, Command::Edit(EditCommand::InsertText { text: ">> ".into() }))
//! .unwrap();
//!
//! let grid = ws.get_viewport_content_styled(view, 0, 10).unwrap();
//! assert!(grid.actual_line_count() > 0);
//! ```
//!
//! # API Visibility
//!
//! `EditorCore` keeps its storage, layout, style, folding, and cursor fields private so hosts
//! cannot bypass synchronization invariants. Use read-only getters such as
//! [`EditorCore::line_index`], [`EditorCore::layout_engine`], [`EditorCore::folding_manager`], and
//! [`EditorCore::viewport_width`] for inspection. Use [`CommandExecutor`], [`EditorStateManager`],
//! [`Workspace`], or narrowly scoped public methods for mutations that must update text, layout,
//! folding, styles, and notifications together. Layout and interval/folding types are exposed from
//! the crate root as facade re-exports rather than through public `layout` or `intervals` modules.
//!
//! # Module Description
//!
//! - [`storage`] - deprecated Piece Table compatibility layer; it is not on the main editing path
//! - [`line_index`] - Rope-based line index and canonical text access facade
//! - [`LayoutEngine`], [`WrapMode`], and related root re-exports - soft wrapping layout facade
//! - [`IntervalTree`], [`FoldingManager`], and related root re-exports - style intervals and code folding facade
//! - [`snapshot`] - Headless snapshot API (HeadlessGrid)
//! - [`commands`] - Unified command interface
//! - [`state`] - State management and query interface
//!
//! # Performance Goals
//!
//! - **Loading**: 1000 line document < 100ms
//! - **insertion**: 100 random insertions < 100ms
//! - **line access**: 1000 line accesses < 10ms
//! - **Memory**: bounded command history with rope-backed text storage on the main editing path
//!
//! # Unicode Support
//!
//! - UTF-8 internal encoding
//! - Proper handling of CJK double-width characters
//! - Public offsets and positions are `char`-indexed Unicode scalar coordinates
//! - Layout columns and snapshot ranges use Unicode scalar positions plus rendered cell widths, not
//! grapheme-cluster indices
//! - Dedicated grapheme cursor/delete commands use UAX #29 boundaries; dedicated word movement and
//! deletion commands use Unicode word boundaries
//! - Editor-friendly word selection and expansion use configurable ASCII token boundaries, treating
//! non-ASCII scalars as single-character word units
//! - `editor-core-lsp` provides UTF-16 code unit coordinate conversion for LSP integrations
//! - `editor-core-sublime` provides optional `.sublime-syntax` syntax highlighting and folding
pub
pub
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use LineEnding;
pub use LineIndex;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use PieceTable;
pub use ;
pub use ;