1use strum_macros::{Display, EnumIter, EnumMessage, EnumString, IntoStaticStr};
2
3use crate::movement::{LinePosition, Movement};
4
5#[derive(
6 Display, EnumString, EnumIter, Clone, PartialEq, Eq, Debug, EnumMessage, IntoStaticStr,
7)]
8pub enum EditCommand {
9 #[strum(message = "Move Line Up")]
10 #[strum(serialize = "move_line_up")]
11 MoveLineUp,
12 #[strum(message = "Move Line Down")]
13 #[strum(serialize = "move_line_down")]
14 MoveLineDown,
15 #[strum(message = "Insert New Line")]
16 #[strum(serialize = "insert_new_line")]
17 InsertNewLine,
18 #[strum(message = "Insert Tab")]
19 #[strum(serialize = "insert_tab")]
20 InsertTab,
21 #[strum(message = "New Line Above")]
22 #[strum(serialize = "new_line_above")]
23 NewLineAbove,
24 #[strum(message = "New Line Below")]
25 #[strum(serialize = "new_line_below")]
26 NewLineBelow,
27 #[strum(message = "Delete Backward")]
28 #[strum(serialize = "delete_backward")]
29 DeleteBackward,
30 #[strum(message = "Delete Forward")]
31 #[strum(serialize = "delete_forward")]
32 DeleteForward,
33 #[strum(message = "Delete Selection")]
34 #[strum(serialize = "delete_selection")]
35 DeleteSelection,
36 #[strum(message = "Delete Line")]
37 #[strum(serialize = "delete_line")]
38 DeleteLine,
39 #[strum(message = "Delete Forward and Insert")]
40 #[strum(serialize = "delete_forward_and_insert")]
41 DeleteForwardAndInsert,
42 #[strum(message = "Delete Word and Insert")]
43 #[strum(serialize = "delete_word_and_insert")]
44 DeleteWordAndInsert,
45 #[strum(message = "Delete Line and Insert")]
46 #[strum(serialize = "delete_line_and_insert")]
47 DeleteLineAndInsert,
48 #[strum(message = "Delete Word Forward")]
49 #[strum(serialize = "delete_word_forward")]
50 DeleteWordForward,
51 #[strum(message = "Delete Word Backward")]
52 #[strum(serialize = "delete_word_backward")]
53 DeleteWordBackward,
54 #[strum(message = "Delete to Beginning of Line")]
55 #[strum(serialize = "delete_to_beginning_of_line")]
56 DeleteToBeginningOfLine,
57 #[strum(message = "Delete to End of Line")]
58 #[strum(serialize = "delete_to_end_of_line")]
59 DeleteToEndOfLine,
60
61 #[strum(message = "Delete to End and Insert")]
62 #[strum(serialize = "delete_to_end_and_insert")]
63 DeleteToEndOfLineAndInsert,
64 #[strum(message = "Join Lines")]
65 #[strum(serialize = "join_lines")]
66 JoinLines,
67 #[strum(message = "Indent Line")]
68 #[strum(serialize = "indent_line")]
69 IndentLine,
70 #[strum(message = "Outdent Line")]
71 #[strum(serialize = "outdent_line")]
72 OutdentLine,
73 #[strum(message = "Toggle Line Comment")]
74 #[strum(serialize = "toggle_line_comment")]
75 ToggleLineComment,
76 #[strum(message = "Undo")]
77 #[strum(serialize = "undo")]
78 Undo,
79 #[strum(message = "Redo")]
80 #[strum(serialize = "redo")]
81 Redo,
82 #[strum(message = "Copy")]
83 #[strum(serialize = "clipboard_copy")]
84 ClipboardCopy,
85 #[strum(message = "Cut")]
86 #[strum(serialize = "clipboard_cut")]
87 ClipboardCut,
88 #[strum(message = "Paste")]
89 #[strum(serialize = "clipboard_paste")]
90 ClipboardPaste,
91 #[strum(message = "Yank")]
92 #[strum(serialize = "yank")]
93 Yank,
94 #[strum(message = "Paste")]
95 #[strum(serialize = "paste")]
96 Paste,
97 #[strum(message = "Paste Before")]
98 #[strum(serialize = "paste_before")]
99 PasteBefore,
100
101 #[strum(message = "Normal Mode")]
102 #[strum(serialize = "normal_mode")]
103 NormalMode,
104 #[strum(message = "Insert Mode")]
105 #[strum(serialize = "insert_mode")]
106 InsertMode,
107 #[strum(message = "Insert First non Blank")]
108 #[strum(serialize = "insert_first_non_blank")]
109 InsertFirstNonBlank,
110 #[strum(message = "Append")]
111 #[strum(serialize = "append")]
112 Append,
113 #[strum(message = "Append End of Line")]
114 #[strum(serialize = "append_end_of_line")]
115 AppendEndOfLine,
116 #[strum(message = "Toggle Visual Mode")]
117 #[strum(serialize = "toggle_visual_mode")]
118 ToggleVisualMode,
119 #[strum(message = "Toggle Linewise Visual Mode")]
120 #[strum(serialize = "toggle_linewise_visual_mode")]
121 ToggleLinewiseVisualMode,
122 #[strum(message = "Toggle Blockwise Visual Mode")]
123 #[strum(serialize = "toggle_blockwise_visual_mode")]
124 ToggleBlockwiseVisualMode,
125 #[strum(message = "Duplicate Line Up")]
126 #[strum(serialize = "duplicate_line_up")]
127 DuplicateLineUp,
128 #[strum(message = "Duplicate Line Down")]
129 #[strum(serialize = "duplicate_line_down")]
130 DuplicateLineDown,
131
132 #[strum(message = "Normalize Line Endings")]
133 #[strum(serialize = "normalize_line_endings")]
134 NormalizeLineEndings,
135}
136
137impl EditCommand {
138 pub fn not_changing_buffer(&self) -> bool {
139 matches!(
140 self,
141 &EditCommand::ClipboardCopy
142 | &EditCommand::Yank
143 | &EditCommand::NormalMode
144 | &EditCommand::InsertMode
145 | &EditCommand::InsertFirstNonBlank
146 | &EditCommand::Append
147 | &EditCommand::AppendEndOfLine
148 | &EditCommand::ToggleVisualMode
149 | &EditCommand::ToggleLinewiseVisualMode
150 | &EditCommand::ToggleBlockwiseVisualMode
151 )
152 }
153}
154
155#[derive(
156 Display, EnumString, EnumIter, Clone, PartialEq, Eq, Debug, EnumMessage, IntoStaticStr,
157)]
158pub enum MoveCommand {
159 #[strum(message = "Down")]
160 #[strum(serialize = "down")]
161 Down,
162 #[strum(message = "Up")]
163 #[strum(serialize = "up")]
164 Up,
165 #[strum(message = "Left")]
166 #[strum(serialize = "left")]
167 Left,
168 #[strum(message = "Right")]
169 #[strum(serialize = "right")]
170 Right,
171 #[strum(message = "Word Backward")]
172 #[strum(serialize = "word_backward")]
173 WordBackward,
174 #[strum(message = "Word Forward")]
175 #[strum(serialize = "word_forward")]
176 WordForward,
177 #[strum(message = "Word End Forward")]
178 #[strum(serialize = "word_end_forward")]
179 WordEndForward,
180 #[strum(message = "Document Start")]
181 #[strum(serialize = "document_start")]
182 DocumentStart,
183 #[strum(message = "Document End")]
184 #[strum(serialize = "document_end")]
185 DocumentEnd,
186 #[strum(message = "Line End")]
187 #[strum(serialize = "line_end")]
188 LineEnd,
189 #[strum(message = "Line Start")]
190 #[strum(serialize = "line_start")]
191 LineStart,
192 #[strum(message = "Line Start non Blank")]
193 #[strum(serialize = "line_start_non_blank")]
194 LineStartNonBlank,
195 #[strum(message = "Go to Line Default Last")]
196 #[strum(serialize = "go_to_line_default_last")]
197 GotoLineDefaultLast,
198 #[strum(message = "Go to Line Default First")]
199 #[strum(serialize = "go_to_line_default_first")]
200 GotoLineDefaultFirst,
201 #[strum(message = "Match Pairs")]
202 #[strum(serialize = "match_pairs")]
203 MatchPairs,
204 #[strum(message = "Next Unmatched Right Bracket")]
205 #[strum(serialize = "next_unmatched_right_bracket")]
206 NextUnmatchedRightBracket,
207 #[strum(message = "Previous Unmatched Left Bracket")]
208 #[strum(serialize = "previous_unmatched_left_bracket")]
209 PreviousUnmatchedLeftBracket,
210 #[strum(message = "Next Unmatched Right Curly Bracket")]
211 #[strum(serialize = "next_unmatched_right_curly_bracket")]
212 NextUnmatchedRightCurlyBracket,
213 #[strum(message = "Previous Unmatched Left Curly Bracket")]
214 #[strum(serialize = "previous_unmatched_left_curly_bracket")]
215 PreviousUnmatchedLeftCurlyBracket,
216 #[strum(message = "Paragraph Forward")]
217 #[strum(serialize = "paragraph_forward")]
218 ParagraphForward,
219 #[strum(message = "Paragraph Backward")]
220 #[strum(serialize = "paragraph_backward")]
221 ParagraphBackward,
222}
223
224impl MoveCommand {
225 pub fn to_movement(&self, count: Option<usize>) -> Movement {
226 use MoveCommand::*;
227 match self {
228 Left => Movement::Left,
229 Right => Movement::Right,
230 Up => Movement::Up,
231 Down => Movement::Down,
232 DocumentStart => Movement::DocumentStart,
233 DocumentEnd => Movement::DocumentEnd,
234 LineStart => Movement::StartOfLine,
235 LineStartNonBlank => Movement::FirstNonBlank,
236 LineEnd => Movement::EndOfLine,
237 GotoLineDefaultFirst => match count {
238 Some(n) => Movement::Line(LinePosition::Line(n)),
239 None => Movement::Line(LinePosition::First),
240 },
241 GotoLineDefaultLast => match count {
242 Some(n) => Movement::Line(LinePosition::Line(n)),
243 None => Movement::Line(LinePosition::Last),
244 },
245 WordBackward => Movement::WordBackward,
246 WordForward => Movement::WordForward,
247 WordEndForward => Movement::WordEndForward,
248 MatchPairs => Movement::MatchPairs,
249 NextUnmatchedRightBracket => Movement::NextUnmatched(')'),
250 PreviousUnmatchedLeftBracket => Movement::PreviousUnmatched('('),
251 NextUnmatchedRightCurlyBracket => Movement::NextUnmatched('}'),
252 PreviousUnmatchedLeftCurlyBracket => Movement::PreviousUnmatched('{'),
253 ParagraphForward => Movement::ParagraphForward,
254 ParagraphBackward => Movement::ParagraphBackward,
255 }
256 }
257}
258
259#[derive(
260 Display, EnumString, EnumIter, Clone, PartialEq, Eq, Debug, EnumMessage, IntoStaticStr,
261)]
262pub enum ScrollCommand {
263 #[strum(message = "Page Up")]
264 #[strum(serialize = "page_up")]
265 PageUp,
266 #[strum(message = "Page Down")]
267 #[strum(serialize = "page_down")]
268 PageDown,
269 #[strum(message = "Scroll Up")]
270 #[strum(serialize = "scroll_up")]
271 ScrollUp,
272 #[strum(message = "Scroll Down")]
273 #[strum(serialize = "scroll_down")]
274 ScrollDown,
275 #[strum(message = "Center of Window")]
276 #[strum(serialize = "center_of_window")]
277 CenterOfWindow,
278 #[strum(message = "Top of Window")]
279 #[strum(serialize = "top_of_window")]
280 TopOfWindow,
281 #[strum(message = "Bottom of Window")]
282 #[strum(serialize = "bottom_of_window")]
283 BottomOfWindow,
284}
285
286#[derive(
287 Display, EnumString, EnumIter, Clone, PartialEq, Eq, Debug, EnumMessage, IntoStaticStr,
288)]
289pub enum FocusCommand {
290 #[strum(message = "Split Vertical")]
291 #[strum(serialize = "split_vertical")]
292 SplitVertical,
293 #[strum(message = "Split Horizontal")]
294 #[strum(serialize = "split_horizontal")]
295 SplitHorizontal,
296 #[strum(message = "Split Exchange")]
297 #[strum(serialize = "split_exchange")]
298 SplitExchange,
299 #[strum(message = "Split Close")]
300 #[strum(serialize = "split_close")]
301 SplitClose,
302 #[strum(message = "Split Right")]
303 #[strum(serialize = "split_right")]
304 SplitRight,
305 #[strum(message = "Split Left")]
306 #[strum(serialize = "split_left")]
307 SplitLeft,
308 #[strum(message = "Split Up")]
309 #[strum(serialize = "split_up")]
310 SplitUp,
311 #[strum(message = "Split Down")]
312 #[strum(serialize = "split_down")]
313 SplitDown,
314 #[strum(message = "Search Whole Word Forward")]
315 #[strum(serialize = "search_whole_word_forward")]
316 SearchWholeWordForward,
317 #[strum(message = "Search Forward")]
318 #[strum(serialize = "search_forward")]
319 SearchForward,
320 #[strum(message = "Search Backward")]
321 #[strum(serialize = "search_backward")]
322 SearchBackward,
323 #[strum(message = "Toggle Case Sensitive Search")]
324 #[strum(serialize = "toggle_case_sensitive_search")]
325 ToggleCaseSensitive,
326 #[strum(message = "Global Search Refresh")]
327 #[strum(serialize = "global_search_refresh")]
328 GlobalSearchRefresh,
329 #[strum(message = "Clear Search")]
330 #[strum(serialize = "clear_search")]
331 ClearSearch,
332 #[strum(message = "Search In View")]
333 #[strum(serialize = "search_in_view")]
334 SearchInView,
335 #[strum(message = "List Select")]
336 #[strum(serialize = "list.select")]
337 ListSelect,
338 #[strum(message = "List Next")]
339 #[strum(serialize = "list.next")]
340 ListNext,
341 #[strum(message = "List Next Page")]
342 #[strum(serialize = "list.next_page")]
343 ListNextPage,
344 #[strum(message = "List Previous")]
345 #[strum(serialize = "list.previous")]
346 ListPrevious,
347 #[strum(message = "List Previous Page")]
348 #[strum(serialize = "list.previous_page")]
349 ListPreviousPage,
350 #[strum(message = "List Expand")]
351 #[strum(serialize = "list.expand")]
352 ListExpand,
353 #[strum(message = "Jump to Next Snippet Placeholder")]
354 #[strum(serialize = "jump_to_next_snippet_placeholder")]
355 JumpToNextSnippetPlaceholder,
356 #[strum(message = "Jump to Previous Snippet Placeholder")]
357 #[strum(serialize = "jump_to_prev_snippet_placeholder")]
358 JumpToPrevSnippetPlaceholder,
359 #[strum(message = "Show Code Actions")]
360 #[strum(serialize = "show_code_actions")]
361 ShowCodeActions,
362 #[strum(message = "Get Completion")]
363 #[strum(serialize = "get_completion")]
364 GetCompletion,
365 #[strum(message = "Get Signature")]
366 #[strum(serialize = "get_signature")]
367 GetSignature,
368 #[strum(message = "Toggle Breakpoint")]
369 #[strum(serialize = "toggle_breakpoint")]
370 ToggleBreakpoint,
371 #[strum(message = "Close Modal")]
373 #[strum(serialize = "modal.close")]
374 ModalClose,
375 #[strum(message = "Go to Definition")]
376 #[strum(serialize = "goto_definition")]
377 GotoDefinition,
378 #[strum(message = "Go to Type Definition")]
379 #[strum(serialize = "goto_type_definition")]
380 GotoTypeDefinition,
381 #[strum(message = "Show Hover")]
382 #[strum(serialize = "show_hover")]
383 ShowHover,
384 #[strum(message = "Go to Next Difference")]
385 #[strum(serialize = "next_diff")]
386 NextDiff,
387 #[strum(message = "Go to Previous Difference")]
388 #[strum(serialize = "previous_diff")]
389 PreviousDiff,
390 #[strum(message = "Toggle Code Lens")]
391 #[strum(serialize = "toggle_code_lens")]
392 ToggleCodeLens,
393 #[strum(message = "Toggle History")]
394 #[strum(serialize = "toggle_history")]
395 ToggleHistory,
396 #[strum(message = "Format Document")]
397 #[strum(serialize = "format_document")]
398 FormatDocument,
399 #[strum(message = "Search")]
400 #[strum(serialize = "search")]
401 Search,
402 #[strum(message = "Focus Replace Editor")]
403 #[strum(serialize = "focus_replace_editor")]
404 FocusReplaceEditor,
405 #[strum(message = "Focus Find Editor")]
406 #[strum(serialize = "focus_find_editor")]
407 FocusFindEditor,
408 #[strum(message = "Inline Find Right")]
409 #[strum(serialize = "inline_find_right")]
410 InlineFindRight,
411 #[strum(message = "Inline Find Left")]
412 #[strum(serialize = "inline_find_left")]
413 InlineFindLeft,
414 #[strum(message = "On Screen Find")]
415 #[strum(serialize = "on_screen_find")]
416 OnScreenFind,
417 #[strum(message = "Create Mark")]
418 #[strum(serialize = "create_mark")]
419 CreateMark,
420 #[strum(message = "Go to Mark")]
421 #[strum(serialize = "go_to_mark")]
422 GoToMark,
423 #[strum(message = "Repeat Last Inline Find")]
424 #[strum(serialize = "repeat_last_inline_find")]
425 RepeatLastInlineFind,
426 #[strum(message = "Save")]
427 #[strum(serialize = "save")]
428 Save,
429 #[strum(message = "Save Without Formatting")]
430 #[strum(serialize = "save_without_format")]
431 SaveWithoutFormatting,
432 #[strum(message = "Save And Exit")]
433 #[strum(serialize = "save_and_exit")]
434 SaveAndExit,
435 #[strum(message = "Force Exit")]
436 #[strum(serialize = "force_exit")]
437 ForceExit,
438 #[strum(message = "Rename Symbol")]
439 #[strum(serialize = "rename_symbol")]
440 Rename,
441 #[strum(message = "Confirm Rename")]
442 #[strum(serialize = "confirm_rename")]
443 ConfirmRename,
444 #[strum(message = "Select Next Syntax Item")]
445 #[strum(serialize = "select_next_syntax_item")]
446 SelectNextSyntaxItem,
447 #[strum(message = "Select Previous Syntax Item")]
448 #[strum(serialize = "select_previous_syntax_item")]
449 SelectPreviousSyntaxItem,
450 #[strum(message = "Open Source File")]
451 #[strum(serialize = "open_source_file")]
452 OpenSourceFile,
453 #[strum(message = "Inline Completion Select")]
454 #[strum(serialize = "inline_completion.select")]
455 InlineCompletionSelect,
456 #[strum(message = "Inline Completion Next")]
457 #[strum(serialize = "inline_completion.next")]
458 InlineCompletionNext,
459 #[strum(message = "Inline Completion Previous")]
460 #[strum(serialize = "inline_completion.previous")]
461 InlineCompletionPrevious,
462 #[strum(message = "Inline Completion Cancel")]
463 #[strum(serialize = "inline_completion.cancel")]
464 InlineCompletionCancel,
465 #[strum(message = "Inline Completion Invoke")]
466 #[strum(serialize = "inline_completion.invoke")]
467 InlineCompletionInvoke,
468}
469
470#[derive(
471 Display, EnumString, EnumIter, Clone, PartialEq, Eq, Debug, EnumMessage, IntoStaticStr,
472)]
473pub enum MotionModeCommand {
474 #[strum(message = "Motion Mode Delete")]
475 #[strum(serialize = "motion_mode_delete")]
476 MotionModeDelete,
477 #[strum(message = "Motion Mode Indent")]
478 #[strum(serialize = "motion_mode_indent")]
479 MotionModeIndent,
480 #[strum(message = "Motion Mode Outdent")]
481 #[strum(serialize = "motion_mode_outdent")]
482 MotionModeOutdent,
483 #[strum(message = "Motion Mode Yank")]
484 #[strum(serialize = "motion_mode_yank")]
485 MotionModeYank,
486}
487
488#[derive(
489 Display, EnumString, EnumIter, Clone, PartialEq, Eq, Debug, EnumMessage, IntoStaticStr,
490)]
491pub enum MultiSelectionCommand {
492 #[strum(message = "Select Undo")]
493 #[strum(serialize = "select_undo")]
494 SelectUndo,
495 #[strum(message = "Insert Cursor Above")]
496 #[strum(serialize = "insert_cursor_above")]
497 InsertCursorAbove,
498 #[strum(message = "Insert Cursor Below")]
499 #[strum(serialize = "insert_cursor_below")]
500 InsertCursorBelow,
501 #[strum(message = "Insert Cursor End of Line")]
502 #[strum(serialize = "insert_cursor_end_of_line")]
503 InsertCursorEndOfLine,
504 #[strum(message = "Select Current Line")]
505 #[strum(serialize = "select_current_line")]
506 SelectCurrentLine,
507 #[strum(message = "Select All Current")]
508 #[strum(serialize = "select_all_current")]
509 SelectAllCurrent,
510 #[strum(message = "Select Next Current")]
511 #[strum(serialize = "select_next_current")]
512 SelectNextCurrent,
513 #[strum(message = "Select Skip Current")]
514 #[strum(serialize = "select_skip_current")]
515 SelectSkipCurrent,
516 #[strum(message = "Select All")]
517 #[strum(serialize = "select_all")]
518 SelectAll,
519}