cellix_input/lib.rs
1//! Input events and the commands they map to. Editing modes are key maps over the same
2//! commands, so views never depend on which mode is active.
3
4mod keymap;
5mod vim;
6
7pub use keymap::simple_keymap;
8pub use vim::{Vim, VimAction, VimMode};
9
10#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
11pub enum Key {
12 Char(char),
13 Enter,
14 Tab,
15 BackTab,
16 Backspace,
17 Delete,
18 Esc,
19 Left,
20 Right,
21 Up,
22 Down,
23 Home,
24 End,
25 PageUp,
26 PageDown,
27 F(u8),
28}
29
30#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
31pub struct Mods {
32 pub ctrl: bool,
33 pub alt: bool,
34 pub shift: bool,
35}
36
37#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
38pub struct KeyEvent {
39 pub key: Key,
40 pub mods: Mods,
41}
42
43impl KeyEvent {
44 pub fn plain(key: Key) -> Self {
45 Self {
46 key,
47 mods: Mods::default(),
48 }
49 }
50
51 pub fn ctrl(c: char) -> Self {
52 Self {
53 key: Key::Char(c),
54 mods: Mods {
55 ctrl: true,
56 ..Mods::default()
57 },
58 }
59 }
60}
61
62#[derive(Clone, Copy, Debug, PartialEq, Eq)]
63pub enum MouseKind {
64 Left,
65 Middle,
66 Right,
67 Up,
68 Drag,
69 /// The pointer moved with no button held.
70 Move,
71 ScrollUp,
72 ScrollDown,
73 /// The wheel tipped sideways, or a trackpad moving across. Only what can move sideways
74 /// uses these: elsewhere a trackpad's drift as it scrolls down would jitter the view.
75 ScrollLeft,
76 ScrollRight,
77}
78
79#[derive(Clone, Copy, Debug, PartialEq)]
80pub struct MouseEvent {
81 pub kind: MouseKind,
82 pub x: u16,
83 pub y: u16,
84 /// `x` with the fraction of a cell, where the terminal reports pixels. Proportional
85 /// text needs this: a cell can hold two thin letters.
86 pub fine_x: f32,
87 /// `y` with the fraction of a row, the same way. Without pixels it's the row's middle,
88 /// so something painted a little past its row is only hit there on its own row.
89 pub fine_y: f32,
90 pub mods: Mods,
91}
92
93impl MouseEvent {
94 /// Where the pointer is, in columns and rows with their fractions.
95 pub fn at(&self) -> (f32, f32) {
96 (self.fine_x, self.fine_y)
97 }
98}
99
100#[derive(Clone, Debug, PartialEq)]
101pub enum Event {
102 Key(KeyEvent),
103 Mouse(MouseEvent),
104 Paste(String),
105 Resize(u16, u16),
106 /// Periodic wake-up for background work such as checking files on disk.
107 Tick,
108}
109
110/// Markdown formatting, as the page's toolbar offers it.
111#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
112pub enum Format {
113 Bold,
114 Italic,
115 Code,
116 Heading,
117 Bullet,
118 Task,
119 Quote,
120 Strikethrough,
121 /// Takes a line's heading, list or quote marker away.
122 PlainText,
123 CodeBlock,
124 Table,
125 Numbered,
126 /// A heading of this level, or plain text at zero.
127 Level(u8),
128 /// A line across the page.
129 Rule,
130 Link,
131}
132
133/// Anything the user can ask for. Each entry is also a command-palette item unless it
134/// needs arguments.
135#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
136pub enum Command {
137 Move(Direction, bool),
138 Newline,
139 /// Types one character, as a key would.
140 Type(char),
141 Indent,
142 Outdent,
143 DeleteBackward,
144 DeleteForward,
145 Undo,
146 Redo,
147 Copy,
148 Cut,
149 Paste,
150 SelectAll,
151 SelectNextMatch,
152 Save,
153 CloseTab,
154 NextTab,
155 PreviousTab,
156 SplitPane,
157 FocusNextPane,
158 ToggleSidebar,
159 QuickOpen,
160 /// Quick Open with `@` typed: the file's symbols, grouped by kind.
161 GoToSymbol,
162 /// Quick Open with `#` typed: symbols across the workspace, from every running server.
163 GoToWorkspaceSymbol,
164 CommandPalette,
165 FindInProject,
166 OpenDiff,
167 AddComment,
168 /// Writes a comment on what's selected and sends it to the agent as it's written.
169 AskAgent,
170 BlameLine,
171 ReplaceInProject,
172 MarkdownPreview,
173 OpenInBrowser,
174 /// Moves the keyboard between the file and the side pane.
175 FocusAgent,
176 /// Builds the paper in view, and shows the PDF.
177 BuildPdf,
178 /// Writes the document as a PDF beside it.
179 ExportPdf,
180 /// The plan in review against the version before it, as suggestions.
181 ComparePlanVersions,
182 /// Scrolls the PDF to the line the caret is on.
183 ShowInPdf,
184 /// The side pane, or the editor in front, takes the window, or gives it back.
185 MaximizePane,
186 MaximizeEditor,
187 /// Wraps long lines of code at the pane's width, or stops: Alt+Z.
188 ToggleWordWrap,
189 /// Folds the region the caret is in, or opens the fold: Ctrl+Shift+[ and ].
190 Fold,
191 Unfold,
192 FoldAll,
193 UnfoldAll,
194 ToggleComment,
195 MoveLineUp,
196 MoveLineDown,
197 DuplicateLine,
198 /// VS Code's Ctrl+Shift+K.
199 DeleteLine,
200 /// A new line below this one, or above, without splitting it: Ctrl+Enter, Ctrl+Shift+Enter.
201 InsertLineBelow,
202 InsertLineAbove,
203 /// Every place the selection or word appears, as cursors: Ctrl+Shift+L.
204 SelectAllMatches,
205 /// A cursor on the line above or below as well: Ctrl+Alt+Up and Down.
206 AddCursorAbove,
207 AddCursorBelow,
208 /// The next suggestion in the document, or the one before: Alt+F5, Shift+Alt+F5.
209 NextChange,
210 PreviousChange,
211 /// The next problem in the file, or the one before: F8, Shift+F8.
212 NextProblem,
213 PreviousProblem,
214 GoToLine,
215 DeleteWordLeft,
216 DeleteWordRight,
217 DeleteToLineStart,
218 DeleteToLineEnd,
219 FindInFile,
220 /// Find with the replace row open.
221 ReplaceInFile,
222 Format(Format),
223 SendToAgent,
224 MentionSelection,
225 AcceptProposal,
226 RejectProposal,
227 ApprovePlan,
228 SendBackPlan,
229 ShowAgents,
230 CloseDock,
231 /// Shows the side pane with what it showed last, or puts it away.
232 TogglePanel,
233 /// Shows the document's headings in the sidebar.
234 ShowOutline,
235 /// Shows what's changed, to stage and commit, in the sidebar.
236 ShowSourceControl,
237 /// Shows what an agent works from in the sidebar: its instructions, skills, hooks and
238 /// what its session read.
239 ShowAgentContext,
240 /// Brings a terminal up in the pane, starting one if there is none, or puts it away.
241 ToggleTerminal,
242 /// Starts another terminal in the pane.
243 NewTerminal,
244 /// Brings the comments up in the pane, or puts them away.
245 ShowComments,
246 /// Brings up what waits for the person in every workspace, or puts it away.
247 ShowInbox,
248 /// Brings the pane's browser up, or starts one, or puts it away.
249 ShowBrowser,
250 /// Brings the list of agents up in the pane, or puts it away.
251 ListAgents,
252 /// Runs the notebook cell the caret is in.
253 RunCell,
254 /// Clears what every cell printed.
255 ClearOutputs,
256 RunAllCells,
257 /// Stops what the notebook's kernel is doing.
258 InterruptKernel,
259 /// Starts the notebook's kernel again, forgetting what it held.
260 RestartKernel,
261 /// Opens the guide to getting started.
262 ShowGuide,
263 /// Starts a new document.
264 NewDocument,
265 /// Keeps typing in this document as suggested changes.
266 ToggleTracking,
267 AcceptChange,
268 RejectChange,
269 /// Turns spelling and grammar checks on or off.
270 ToggleSpelling,
271 AcceptAllChanges,
272 RejectAllChanges,
273 ReviewPreviousTurn,
274 UndoTurn,
275 /// The Task page: the agent work here as a timeline.
276 ShowAgentTask,
277 Commit,
278 OpenClaude,
279 OpenCodex,
280 /// Moves to the next workspace in the bar along the bottom.
281 NextWorkspace,
282 PreviousWorkspace,
283 /// Opens another folder beside this one, as a workspace of its own.
284 OpenWorkspace,
285 OpenGemini,
286 /// Opens the transcript of the agent in the side pane as a page.
287 OpenTranscript,
288 OpenSettings,
289 SwitchBranch,
290 /// Folders and files opened lately, to open again.
291 OpenRecent,
292 /// The project's tasks, to run one in the side pane: VS Code's Run Task.
293 RunTask,
294 /// The default build task: Ctrl+Shift+B.
295 RunBuildTask,
296 RerunLastTask,
297 GoToDefinition,
298 /// The language server's fixes and refactors at the caret: Ctrl+. in VS Code.
299 QuickFix,
300 /// What the language server says about the symbol at the caret.
301 ShowHover,
302 /// Back to where the last jump left from, as VS Code's Go Back and Vim's Ctrl+O.
303 GoBack,
304 GoForward,
305 GoToReferences,
306 FormatDocument,
307 Complete,
308 RenameSymbol,
309 /// Selects this many whole lines from the cursor.
310 SelectLines(usize),
311 /// Pastes after the cursor, or below it for a copied line.
312 PasteLine,
313 /// Git: puts the changes aside, with untracked files too, or only what's staged.
314 Stash,
315 StashUntracked,
316 StashStaged,
317 /// Brings the newest stash back and drops it.
318 PopStash,
319 /// Picks a stash to apply, pop or drop.
320 ApplyStash,
321 PickStashToPop,
322 DropStash,
323 /// Compares the file in view with a branch, a commit or the clipboard.
324 CompareWith,
325 /// The repository's commits, drawn as a graph.
326 ShowHistory,
327 /// The commits that changed the file in view.
328 FileHistory,
329 /// Settles the conflict at the caret, keeping one side or both.
330 AcceptCurrent,
331 AcceptIncoming,
332 AcceptBoth,
333 /// The conflict at the caret, its two sides in the diff.
334 CompareConflict,
335 NextConflict,
336 PreviousConflict,
337 /// Gives up the merge, rebase, cherry-pick or revert under way.
338 AbortMerge,
339 Cancel,
340 Quit,
341}
342
343/// A cursor movement, independent of the rope model.
344#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
345pub enum Direction {
346 Left,
347 Right,
348 Up,
349 Down,
350 WordLeft,
351 WordRight,
352 LineStart,
353 /// Column zero, where `LineStart` stops at the indent first.
354 LineColumnZero,
355 LineEnd,
356 Top,
357 Bottom,
358 PageUp,
359 PageDown,
360 /// The start of the next word, as Vim's `w`.
361 NextWordStart,
362 /// To a character on the line: forward or back, and stopping just before it.
363 FindChar(char, bool, bool),
364}