actions.rs

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