Skip to main content

tsu_editor/
action.rs

1use serde::{Deserialize, Serialize};
2
3use crate::config::KeyAction;
4use crate::editor::Mode;
5
6#[derive(Debug, Serialize, Deserialize, Clone)]
7/// The collection of handled editor actions
8///
9/// This is primarily leveraged by the main editor processing loop for mapping user input sequences to handleable actions
10pub enum Action {
11    /// Closes the application
12    Quit(bool),
13    /// Writes the current buffer to a file
14    Save,
15    /// Writes the current buffer to the file provided as an argument to the ':w' command
16    SaveAs(String),
17    /// Reverses the previous undoable action
18    Undo,
19    /// Reverses multiple previous undoable actions simultaneously
20    UndoMultiple(Vec<Action>),
21    /// Moves the current line to the center of the view
22    CenterView,
23
24    /// Move the cursor up
25    MoveUp,
26    /// Move the cursor down
27    MoveDown,
28    /// Move the cursor left
29    MoveLeft,
30    /// Move the cursor right
31    MoveRight,
32    /// Move to a specific (x, y) position in the buffer
33    MoveTo(usize, usize),
34    /// Move the cursor to the top of the buffer
35    MoveToTop,
36    /// Move the cursor to the bottom of the buffer
37    MoveToBottom,
38    /// Move the cursor to the end of the current line
39    MoveToLineEnd,
40    /// Move the cursor to the beginning of the current line
41    MoveToLineStart,
42    /// Move the current line to the center of the view
43    MoveLineToViewCenter,
44    /// Move the current line to the bottom of the view
45    MoveLineToViewBottom,
46    /// Move the viewport down one line
47    MoveViewDownOneLine,
48    /// Move the viewport up one line
49    MoveViewUpOneLine,
50    /// Move the cursor to the bottom of the buffer
51    MoveToBottomOfBuffer,
52    /// Move the cursor to the top of the buffer
53    MoveToTopOfBuffer,
54
55    /// Move the view up one "page"
56    PageUp,
57    /// Move the view down one "page"
58    PageDown,
59
60    /// Run a command given a string input in command mode
61    Command(String),
62
63    /// Insert a character at the current location of the cursor
64    InsertCharAtCursor(char),
65    /// Remove a character at the specified position
66    RemoveCharAt(usize, usize),
67    /// Insert a line above the cursor
68    InsertLineAbove,
69    /// Insert a line below the cursor
70    InsertLineBelow,
71    /// Insert a line at the specified y coordinate
72    InsertLineAt(usize, Option<String>),
73    /// Insert a new line character ('\n')
74    InsertNewLine,
75
76    /// Replace the contents of the line at the specified y coordinate with another string
77    ReplaceLineAt(usize, String),
78
79    /// Delete the character behind the cursor
80    DeletePreviousChar,
81    /// Delete the character at the cursor
82    DeleteCharAtCursor,
83    /// Delete the line where the cursor is currently located
84    DeleteCurrentLine,
85    /// Delete the line at the specified y coordinate
86    DeleteLineAt(usize),
87
88    /// Go to the specified line provided in command mode
89    GoToLine(usize),
90
91    /// Change to mode
92    EnterMode(Mode),
93    /// Store the first key in a multi-character command sequence
94    SetWaitingKey(Box<KeyAction>),
95}