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 BlameLine,
169 ReplaceInProject,
170 MarkdownPreview,
171 OpenInBrowser,
172 /// Moves the keyboard between the file and the side pane.
173 FocusAgent,
174 /// Builds the paper in view, and shows the PDF.
175 BuildPdf,
176 /// Writes the document as a PDF beside it.
177 ExportPdf,
178 /// The plan in review against the version before it, as suggestions.
179 ComparePlanVersions,
180 /// Scrolls the PDF to the line the caret is on.
181 ShowInPdf,
182 /// The side pane, or the editor in front, takes the window, or gives it back.
183 MaximizePane,
184 MaximizeEditor,
185 /// Wraps long lines of code at the pane's width, or stops: Alt+Z.
186 ToggleWordWrap,
187 /// Folds the region the caret is in, or opens the fold: Ctrl+Shift+[ and ].
188 Fold,
189 Unfold,
190 FoldAll,
191 UnfoldAll,
192 ToggleComment,
193 MoveLineUp,
194 MoveLineDown,
195 DuplicateLine,
196 /// VS Code's Ctrl+Shift+K.
197 DeleteLine,
198 /// A new line below this one, or above, without splitting it: Ctrl+Enter, Ctrl+Shift+Enter.
199 InsertLineBelow,
200 InsertLineAbove,
201 /// Every place the selection or word appears, as cursors: Ctrl+Shift+L.
202 SelectAllMatches,
203 /// A cursor on the line above or below as well: Ctrl+Alt+Up and Down.
204 AddCursorAbove,
205 AddCursorBelow,
206 /// The next suggestion in the document, or the one before: Alt+F5, Shift+Alt+F5.
207 NextChange,
208 PreviousChange,
209 /// The next problem in the file, or the one before: F8, Shift+F8.
210 NextProblem,
211 PreviousProblem,
212 GoToLine,
213 DeleteWordLeft,
214 DeleteWordRight,
215 DeleteToLineStart,
216 DeleteToLineEnd,
217 FindInFile,
218 /// Find with the replace row open.
219 ReplaceInFile,
220 Format(Format),
221 SendToAgent,
222 MentionSelection,
223 AcceptProposal,
224 RejectProposal,
225 ApprovePlan,
226 SendBackPlan,
227 ShowAgents,
228 CloseDock,
229 /// Shows the side pane with what it showed last, or puts it away.
230 TogglePanel,
231 /// Shows the document's headings in the sidebar.
232 ShowOutline,
233 /// Shows what's changed, to stage and commit, in the sidebar.
234 ShowSourceControl,
235 /// Shows what an agent works from in the sidebar: its instructions, skills, hooks and
236 /// what its session read.
237 ShowAgentContext,
238 /// Brings a terminal up in the pane, starting one if there is none, or puts it away.
239 ToggleTerminal,
240 /// Starts another terminal in the pane.
241 NewTerminal,
242 /// Brings the comments up in the pane, or puts them away.
243 ShowComments,
244 /// Brings up what waits for the person in every workspace, or puts it away.
245 ShowInbox,
246 /// Brings the pane's browser up, or starts one, or puts it away.
247 ShowBrowser,
248 /// Brings the list of agents up in the pane, or puts it away.
249 ListAgents,
250 /// Runs the notebook cell the caret is in.
251 RunCell,
252 /// Clears what every cell printed.
253 ClearOutputs,
254 RunAllCells,
255 /// Stops what the notebook's kernel is doing.
256 InterruptKernel,
257 /// Starts the notebook's kernel again, forgetting what it held.
258 RestartKernel,
259 /// Opens the guide to getting started.
260 ShowGuide,
261 /// Starts a new document.
262 NewDocument,
263 /// Keeps typing in this document as suggested changes.
264 ToggleTracking,
265 AcceptChange,
266 RejectChange,
267 /// Turns spelling and grammar checks on or off.
268 ToggleSpelling,
269 AcceptAllChanges,
270 RejectAllChanges,
271 ReviewPreviousTurn,
272 UndoTurn,
273 /// The Task page: the agent work here as a timeline.
274 ShowAgentTask,
275 Commit,
276 OpenClaude,
277 OpenCodex,
278 /// Moves to the next workspace in the bar along the bottom.
279 NextWorkspace,
280 PreviousWorkspace,
281 /// Opens another folder beside this one, as a workspace of its own.
282 OpenWorkspace,
283 OpenGemini,
284 /// Opens the transcript of the agent in the side pane as a page.
285 OpenTranscript,
286 OpenSettings,
287 SwitchBranch,
288 /// Folders and files opened lately, to open again.
289 OpenRecent,
290 /// The project's tasks, to run one in the side pane: VS Code's Run Task.
291 RunTask,
292 /// The default build task: Ctrl+Shift+B.
293 RunBuildTask,
294 RerunLastTask,
295 GoToDefinition,
296 /// The language server's fixes and refactors at the caret: Ctrl+. in VS Code.
297 QuickFix,
298 /// What the language server says about the symbol at the caret.
299 ShowHover,
300 /// Back to where the last jump left from, as VS Code's Go Back and Vim's Ctrl+O.
301 GoBack,
302 GoForward,
303 GoToReferences,
304 FormatDocument,
305 Complete,
306 RenameSymbol,
307 /// Selects this many whole lines from the cursor.
308 SelectLines(usize),
309 /// Pastes after the cursor, or below it for a copied line.
310 PasteLine,
311 /// Git: puts the changes aside, with untracked files too, or only what's staged.
312 Stash,
313 StashUntracked,
314 StashStaged,
315 /// Brings the newest stash back and drops it.
316 PopStash,
317 /// Picks a stash to apply, pop or drop.
318 ApplyStash,
319 PickStashToPop,
320 DropStash,
321 /// Compares the file in view with a branch, a commit or the clipboard.
322 CompareWith,
323 /// The repository's commits, drawn as a graph.
324 ShowHistory,
325 /// The commits that changed the file in view.
326 FileHistory,
327 /// Settles the conflict at the caret, keeping one side or both.
328 AcceptCurrent,
329 AcceptIncoming,
330 AcceptBoth,
331 /// The conflict at the caret, its two sides in the diff.
332 CompareConflict,
333 NextConflict,
334 PreviousConflict,
335 /// Gives up the merge, rebase, cherry-pick or revert under way.
336 AbortMerge,
337 Cancel,
338 Quit,
339}
340
341/// A cursor movement, independent of the rope model.
342#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
343pub enum Direction {
344 Left,
345 Right,
346 Up,
347 Down,
348 WordLeft,
349 WordRight,
350 LineStart,
351 /// Column zero, where `LineStart` stops at the indent first.
352 LineColumnZero,
353 LineEnd,
354 Top,
355 Bottom,
356 PageUp,
357 PageDown,
358 /// The start of the next word, as Vim's `w`.
359 NextWordStart,
360 /// To a character on the line: forward or back, and stopping just before it.
361 FindChar(char, bool, bool),
362}