floem_editor_core/
command.rs

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