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
//! # `canvist_core`
//!
//! The platform-agnostic editing engine behind canvist. It sits between the
//! document model ([`canvist_model`]) and the platform hosts, and owns
//! everything about *editing* that does not depend on pixels:
//!
//! - [`EditorState`]: the document, the selection, stored marks, and IME
//! composition, changed only through [`EditorState::change`] and
//! [`EditorState::apply_steps`].
//! - [`commands`]: plain functions such as typing, deleting by grapheme or
//! word, splitting and joining blocks, lists, marks, and paste.
//! - [`motion`]: caret movement by grapheme, word, line, and document. Lines
//! come from a [`LineNavigator`], which the layout engine implements and
//! hosts pass per event through [`Env::new`]; [`Env::headless`] falls back
//! to [`ParagraphNavigator`]. [`Caret`] carries the [`Affinity`] that
//! tells the two sides of a soft wrap apart.
//! - [`Editor`]: the state plus [`History`], a [`Keymap`] with platform-aware
//! `Mod`, [`InputRule`]s, and [`PasteRule`]s, all contributed by
//! [`Extension`]s. [`BaseKeymap`] binds the platform's standard keys and
//! [`UndoInputRule`] lets Backspace take back an input rule.
//! - A headless, typed API: [`EditorBuilder::add`] returns each extension's
//! typed handle; [`CommandSpec`] and [`QuerySpec`] give dynamic hosts
//! argument-checked named commands and queries; [`Editor::metadata`]
//! describes all of it for binding generators; and [`Editor::can`] and
//! [`Editor::chain`] dry-run or combine commands without side effects,
//! on top of the model's exact savepoints.
//! - Building blocks for extensions: [`query`] reads the selection's
//! surroundings by type name, and [`SimpleMark`] describes a mark that
//! only switches on and off.
//!
//! Grapheme and word boundaries follow Unicode (UAX #29), and inline embeds
//! behave as single atoms everywhere.
//!
//! # Example
//!
//! ```
//! use std::sync::Arc;
//!
//! use canvist_core::EditorState;
//! use canvist_core::commands;
//! use canvist_model::BlockSpec;
//! use canvist_model::Document;
//! use canvist_model::Schema;
//!
//! let schema = Arc::new(Schema::builder().block(BlockSpec::text("paragraph")).build()?);
//! let mut state = EditorState::new(Document::new(schema, 1))?;
//!
//! commands::insert_text(&mut state, "Hello")?;
//! commands::split_block(&mut state)?;
//! commands::insert_text(&mut state, "world")?;
//!
//! assert_eq!(state.doc().plain_text(), "Hello\nworld");
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! An [`Editor`] adds keymaps, rules, and history on top:
//!
//! ```
//! use std::time::Duration;
//!
//! use canvist_core::BaseKeymap;
//! use canvist_core::Editor;
//! use canvist_core::Env;
//! use canvist_core::Extension;
//! use canvist_core::KeyPress;
//! use canvist_model::BlockSpec;
//! use canvist_model::SchemaBuilder;
//!
//! struct Paragraphs;
//!
//! impl Extension for Paragraphs {
//! fn name(&self) -> &'static str {
//! "paragraphs"
//! }
//!
//! fn schema(&self, schema: SchemaBuilder) -> SchemaBuilder {
//! schema.block(BlockSpec::text("paragraph"))
//! }
//! }
//!
//! let mut editor = Editor::builder().extension(Paragraphs).extension(BaseKeymap).build()?;
//! let mut env = Env::headless(Duration::ZERO);
//!
//! editor.insert_text("Hi", &mut env)?;
//! editor.handle_key(KeyPress::plain("Enter"), &mut env)?;
//! editor.undo(&mut env)?;
//!
//! assert_eq!(editor.state().doc().plain_text(), "Hi");
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
pub use Adornment;
pub use BaseKeymap;
pub use UndoInputRule;
pub use CommandResult;
pub use Slice;
pub use Command;
pub use Context;
pub use command;
pub use redo;
pub use undo;
pub use undo_input_rule;
pub use Dictation;
pub use Settling;
pub use Transcript;
pub use Editor;
pub use EditorBuilder;
pub use Env;
pub use EditorError;
pub use Binding;
pub use Extension;
pub use UpdateFilter;
pub use block_type;
pub use embed_type;
pub use mark_type;
pub use History;
pub use HistoryConfig;
pub use UndoGrouping;
pub use UndoHistory;
pub use KeyPress;
pub use Keymap;
pub use Modifiers;
pub use Platform;
pub use parse_binding;
pub use CommandMeta;
pub use ExtensionMeta;
pub use Field;
pub use NodeKind;
pub use NodeMeta;
pub use QueryMeta;
pub use ValueType;
pub use value_to_json;
pub use Direction;
pub use Unit;
pub use Affinity;
pub use Caret;
pub use LineEdge;
pub use LineNavigator;
pub use NavigationError;
pub use ParagraphNavigator;
pub use VerticalDirection;
pub use VerticalMotion;
pub use DEFAULT_LOOKBACK;
pub use InputRule;
pub use Lookback;
pub use MarkAttrs;
pub use PasteRule;
pub use RULE_CONTEXT;
pub use RuleHandler;
pub use RuleInput;
pub use RuleMatch;
pub use MarkHandle;
pub use SimpleMark;
pub use Args;
pub use CommandBuilder;
pub use CommandSpec;
pub use QueryFn;
pub use QuerySpec;
pub use Composition;
pub use EditorState;
pub use EditKind;
pub use EditorTransaction;
pub use Origin;
pub use Update;
pub use Chain;
pub use Registration;
pub use TypedExtension;