actions.rs

  1//! This module contains all actions supported by [`Editor`].
  2use super::*;
  3use gpui::{action_aliases, action_as};
  4use util::serde::default_true;
  5
  6#[derive(PartialEq, Clone, Deserialize, Default)]
  7pub struct SelectNext {
  8    #[serde(default)]
  9    pub replace_newest: bool,
 10}
 11
 12#[derive(PartialEq, Clone, Deserialize, Default)]
 13pub struct SelectPrevious {
 14    #[serde(default)]
 15    pub replace_newest: bool,
 16}
 17
 18#[derive(PartialEq, Clone, Deserialize, Default)]
 19pub struct MoveToBeginningOfLine {
 20    #[serde(default = "default_true")]
 21    pub stop_at_soft_wraps: bool,
 22}
 23
 24#[derive(PartialEq, Clone, Deserialize, Default)]
 25pub struct SelectToBeginningOfLine {
 26    #[serde(default)]
 27    pub(super) stop_at_soft_wraps: bool,
 28}
 29
 30#[derive(PartialEq, Clone, Deserialize, Default)]
 31pub struct MovePageUp {
 32    #[serde(default)]
 33    pub(super) center_cursor: bool,
 34}
 35
 36#[derive(PartialEq, Clone, Deserialize, Default)]
 37pub struct MovePageDown {
 38    #[serde(default)]
 39    pub(super) center_cursor: bool,
 40}
 41
 42#[derive(PartialEq, Clone, Deserialize, Default)]
 43pub struct MoveToEndOfLine {
 44    #[serde(default = "default_true")]
 45    pub stop_at_soft_wraps: bool,
 46}
 47
 48#[derive(PartialEq, Clone, Deserialize, Default)]
 49pub struct SelectToEndOfLine {
 50    #[serde(default)]
 51    pub(super) stop_at_soft_wraps: bool,
 52}
 53
 54#[derive(PartialEq, Clone, Deserialize, Default)]
 55pub struct ToggleCodeActions {
 56    // Display row from which the action was deployed.
 57    #[serde(default)]
 58    pub deployed_from_indicator: Option<DisplayRow>,
 59}
 60
 61#[derive(PartialEq, Clone, Deserialize, Default)]
 62pub struct ConfirmCompletion {
 63    #[serde(default)]
 64    pub item_ix: Option<usize>,
 65}
 66
 67#[derive(PartialEq, Clone, Deserialize, Default)]
 68pub struct ComposeCompletion {
 69    #[serde(default)]
 70    pub item_ix: Option<usize>,
 71}
 72
 73#[derive(PartialEq, Clone, Deserialize, Default)]
 74pub struct ConfirmCodeAction {
 75    #[serde(default)]
 76    pub item_ix: Option<usize>,
 77}
 78
 79#[derive(PartialEq, Clone, Deserialize, Default)]
 80pub struct ToggleComments {
 81    #[serde(default)]
 82    pub advance_downwards: bool,
 83    #[serde(default)]
 84    pub ignore_indent: bool,
 85}
 86
 87#[derive(PartialEq, Clone, Deserialize, Default)]
 88pub struct FoldAt {
 89    pub buffer_row: MultiBufferRow,
 90}
 91
 92#[derive(PartialEq, Clone, Deserialize, Default)]
 93pub struct UnfoldAt {
 94    pub buffer_row: MultiBufferRow,
 95}
 96
 97#[derive(PartialEq, Clone, Deserialize, Default)]
 98pub struct MoveUpByLines {
 99    #[serde(default)]
100    pub(super) lines: u32,
101}
102
103#[derive(PartialEq, Clone, Deserialize, Default)]
104pub struct MoveDownByLines {
105    #[serde(default)]
106    pub(super) lines: u32,
107}
108
109#[derive(PartialEq, Clone, Deserialize, Default)]
110pub struct SelectUpByLines {
111    #[serde(default)]
112    pub(super) lines: u32,
113}
114
115#[derive(PartialEq, Clone, Deserialize, Default)]
116pub struct SelectDownByLines {
117    #[serde(default)]
118    pub(super) lines: u32,
119}
120
121#[derive(PartialEq, Clone, Deserialize, Default)]
122pub struct ExpandExcerpts {
123    #[serde(default)]
124    pub(super) lines: u32,
125}
126
127#[derive(PartialEq, Clone, Deserialize, Default)]
128pub struct ExpandExcerptsUp {
129    #[serde(default)]
130    pub(super) lines: u32,
131}
132
133#[derive(PartialEq, Clone, Deserialize, Default)]
134pub struct ExpandExcerptsDown {
135    #[serde(default)]
136    pub(super) lines: u32,
137}
138#[derive(PartialEq, Clone, Deserialize, Default)]
139pub struct ShowCompletions {
140    #[serde(default)]
141    pub(super) trigger: Option<String>,
142}
143
144#[derive(PartialEq, Clone, Deserialize, Default)]
145pub struct HandleInput(pub String);
146
147#[derive(PartialEq, Clone, Deserialize, Default)]
148pub struct DeleteToNextWordEnd {
149    #[serde(default)]
150    pub ignore_newlines: bool,
151}
152
153#[derive(PartialEq, Clone, Deserialize, Default)]
154pub struct DeleteToPreviousWordStart {
155    #[serde(default)]
156    pub ignore_newlines: bool,
157}
158
159#[derive(PartialEq, Clone, Deserialize, Default)]
160pub struct FoldAtLevel {
161    pub level: u32,
162}
163
164#[derive(PartialEq, Clone, Deserialize, Default)]
165pub struct SpawnNearestTask {
166    #[serde(default)]
167    pub reveal: task::RevealStrategy,
168}
169
170#[derive(Debug, PartialEq, Eq, Clone, Copy, Deserialize, Default)]
171pub enum UuidVersion {
172    #[default]
173    V4,
174    V7,
175}
176
177impl_actions!(
178    editor,
179    [
180        ComposeCompletion,
181        ConfirmCodeAction,
182        ConfirmCompletion,
183        DeleteToNextWordEnd,
184        DeleteToPreviousWordStart,
185        ExpandExcerpts,
186        ExpandExcerptsDown,
187        ExpandExcerptsUp,
188        FoldAt,
189        HandleInput,
190        MoveDownByLines,
191        MovePageDown,
192        MovePageUp,
193        MoveToBeginningOfLine,
194        MoveToEndOfLine,
195        MoveUpByLines,
196        SelectDownByLines,
197        SelectNext,
198        SelectPrevious,
199        SelectToBeginningOfLine,
200        SelectToEndOfLine,
201        SelectUpByLines,
202        SpawnNearestTask,
203        ShowCompletions,
204        ToggleCodeActions,
205        ToggleComments,
206        UnfoldAt,
207        FoldAtLevel,
208    ]
209);
210
211gpui::actions!(
212    editor,
213    [
214        AcceptInlineCompletion,
215        AcceptPartialCopilotSuggestion,
216        AcceptPartialInlineCompletion,
217        AddSelectionAbove,
218        AddSelectionBelow,
219        ApplyAllDiffHunks,
220        ApplyDiffHunk,
221        Backspace,
222        Cancel,
223        CancelLanguageServerWork,
224        ConfirmRename,
225        ContextMenuFirst,
226        ContextMenuLast,
227        ContextMenuNext,
228        ContextMenuPrev,
229        ConvertToKebabCase,
230        ConvertToLowerCamelCase,
231        ConvertToLowerCase,
232        ConvertToOppositeCase,
233        ConvertToSnakeCase,
234        ConvertToTitleCase,
235        ConvertToUpperCamelCase,
236        ConvertToUpperCase,
237        Copy,
238        CopyFileLocation,
239        CopyHighlightJson,
240        CopyPath,
241        CopyPermalinkToLine,
242        CopyRelativePath,
243        Cut,
244        CutToEndOfLine,
245        Delete,
246        DeleteLine,
247        DeleteToBeginningOfLine,
248        DeleteToEndOfLine,
249        DeleteToNextSubwordEnd,
250        DeleteToPreviousSubwordStart,
251        DisplayCursorNames,
252        DuplicateLineDown,
253        DuplicateLineUp,
254        DuplicateSelection,
255        ExpandAllHunkDiffs,
256        ExpandMacroRecursively,
257        FindAllReferences,
258        Fold,
259        FoldAll,
260        FoldFunctionBodies,
261        FoldRecursive,
262        FoldSelectedRanges,
263        ToggleFold,
264        ToggleFoldRecursive,
265        Format,
266        FormatSelections,
267        GoToDeclaration,
268        GoToDeclarationSplit,
269        GoToDefinition,
270        GoToDefinitionSplit,
271        GoToDiagnostic,
272        GoToHunk,
273        GoToImplementation,
274        GoToImplementationSplit,
275        GoToPrevDiagnostic,
276        GoToPrevHunk,
277        GoToTypeDefinition,
278        GoToTypeDefinitionSplit,
279        HalfPageDown,
280        HalfPageUp,
281        Hover,
282        Indent,
283        InsertUuidV4,
284        InsertUuidV7,
285        JoinLines,
286        KillRingCut,
287        KillRingYank,
288        LineDown,
289        LineUp,
290        MoveDown,
291        MoveLeft,
292        MoveLineDown,
293        MoveLineUp,
294        MoveRight,
295        MoveToBeginning,
296        MoveToEnclosingBracket,
297        MoveToEnd,
298        MoveToEndOfParagraph,
299        MoveToNextSubwordEnd,
300        MoveToNextWordEnd,
301        MoveToPreviousSubwordStart,
302        MoveToPreviousWordStart,
303        MoveToStartOfParagraph,
304        MoveUp,
305        Newline,
306        NewlineAbove,
307        NewlineBelow,
308        NextInlineCompletion,
309        NextScreen,
310        OpenContextMenu,
311        OpenExcerpts,
312        OpenExcerptsSplit,
313        OpenProposedChangesEditor,
314        OpenDocs,
315        OpenPermalinkToLine,
316        OpenUrl,
317        Outdent,
318        AutoIndent,
319        PageDown,
320        PageUp,
321        Paste,
322        PreviousInlineCompletion,
323        Redo,
324        RedoSelection,
325        Rename,
326        RestartLanguageServer,
327        RevealInFileManager,
328        ReverseLines,
329        RevertFile,
330        ReloadFile,
331        RevertSelectedHunks,
332        Rewrap,
333        ScrollCursorBottom,
334        ScrollCursorCenter,
335        ScrollCursorCenterTopBottom,
336        ScrollCursorTop,
337        SelectAll,
338        SelectAllMatches,
339        SelectDown,
340        SelectEnclosingSymbol,
341        SelectLargerSyntaxNode,
342        SelectLeft,
343        SelectLine,
344        SelectPageDown,
345        SelectPageUp,
346        SelectRight,
347        SelectSmallerSyntaxNode,
348        SelectToBeginning,
349        SelectToEnd,
350        SelectToEndOfParagraph,
351        SelectToNextSubwordEnd,
352        SelectToNextWordEnd,
353        SelectToPreviousSubwordStart,
354        SelectToPreviousWordStart,
355        SelectToStartOfParagraph,
356        SelectUp,
357        ShowCharacterPalette,
358        ShowInlineCompletion,
359        ShowSignatureHelp,
360        ShuffleLines,
361        SortLinesCaseInsensitive,
362        SortLinesCaseSensitive,
363        SplitSelectionIntoLines,
364        SwitchSourceHeader,
365        Tab,
366        TabPrev,
367        ToggleAutoSignatureHelp,
368        ToggleGitBlame,
369        ToggleGitBlameInline,
370        ToggleHunkDiff,
371        ToggleIndentGuides,
372        ToggleInlayHints,
373        ToggleInlineCompletions,
374        ToggleLineNumbers,
375        ToggleRelativeLineNumbers,
376        ToggleSelectionMenu,
377        ToggleSoftWrap,
378        ToggleTabBar,
379        Transpose,
380        Undo,
381        UndoSelection,
382        UnfoldAll,
383        UnfoldLines,
384        UnfoldRecursive,
385        UniqueLinesCaseInsensitive,
386        UniqueLinesCaseSensitive,
387    ]
388);
389
390action_as!(go_to_line, ToggleGoToLine as Toggle);
391
392action_aliases!(editor, OpenSelectedFilename, [OpenFile]);