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        FindNextMatch,
287        FindPreviousMatch,
288        Fold,
289        FoldAll,
290        FoldFunctionBodies,
291        FoldRecursive,
292        FoldSelectedRanges,
293        ToggleFold,
294        ToggleFoldRecursive,
295        Format,
296        FormatSelections,
297        GoToDeclaration,
298        GoToDeclarationSplit,
299        GoToDefinition,
300        GoToDefinitionSplit,
301        GoToDiagnostic,
302        GoToHunk,
303        GoToPreviousHunk,
304        GoToImplementation,
305        GoToImplementationSplit,
306        GoToNextChange,
307        GoToPreviousChange,
308        GoToPreviousDiagnostic,
309        GoToTypeDefinition,
310        GoToTypeDefinitionSplit,
311        HalfPageDown,
312        HalfPageUp,
313        Hover,
314        Indent,
315        InsertUuidV4,
316        InsertUuidV7,
317        JoinLines,
318        KillRingCut,
319        KillRingYank,
320        LineDown,
321        LineUp,
322        MoveDown,
323        MoveLeft,
324        MoveLineDown,
325        MoveLineUp,
326        MoveRight,
327        MoveToBeginning,
328        MoveToEnclosingBracket,
329        MoveToEnd,
330        MoveToEndOfParagraph,
331        MoveToNextSubwordEnd,
332        MoveToNextWordEnd,
333        MoveToPreviousSubwordStart,
334        MoveToPreviousWordStart,
335        MoveToStartOfParagraph,
336        MoveToStartOfExcerpt,
337        MoveToStartOfNextExcerpt,
338        MoveToEndOfExcerpt,
339        MoveToEndOfPreviousExcerpt,
340        MoveUp,
341        Newline,
342        NewlineAbove,
343        NewlineBelow,
344        NextEditPrediction,
345        NextScreen,
346        OpenContextMenu,
347        OpenExcerpts,
348        OpenExcerptsSplit,
349        OpenProposedChangesEditor,
350        OpenDocs,
351        OpenPermalinkToLine,
352        OpenSelectionsInMultibuffer,
353        OpenUrl,
354        OrganizeImports,
355        Outdent,
356        AutoIndent,
357        PageDown,
358        PageUp,
359        Paste,
360        PreviousEditPrediction,
361        Redo,
362        RedoSelection,
363        Rename,
364        RestartLanguageServer,
365        RevealInFileManager,
366        ReverseLines,
367        RevertFile,
368        ReloadFile,
369        Rewrap,
370        ScrollCursorBottom,
371        ScrollCursorCenter,
372        ScrollCursorCenterTopBottom,
373        ScrollCursorTop,
374        SelectAll,
375        SelectAllMatches,
376        SelectToStartOfExcerpt,
377        SelectToStartOfNextExcerpt,
378        SelectToEndOfExcerpt,
379        SelectToEndOfPreviousExcerpt,
380        SelectDown,
381        SelectEnclosingSymbol,
382        SelectLargerSyntaxNode,
383        SelectLeft,
384        SelectLine,
385        SelectPageDown,
386        SelectPageUp,
387        SelectRight,
388        SelectSmallerSyntaxNode,
389        SelectToBeginning,
390        SelectToEnd,
391        SelectToEndOfParagraph,
392        SelectToNextSubwordEnd,
393        SelectToNextWordEnd,
394        SelectToPreviousSubwordStart,
395        SelectToPreviousWordStart,
396        SelectToStartOfParagraph,
397        SelectUp,
398        ShowCharacterPalette,
399        ShowEditPrediction,
400        ShowSignatureHelp,
401        ShowWordCompletions,
402        ShuffleLines,
403        SortLinesCaseInsensitive,
404        SortLinesCaseSensitive,
405        SplitSelectionIntoLines,
406        StopLanguageServer,
407        SwitchSourceHeader,
408        Tab,
409        Backtab,
410        ToggleBreakpoint,
411        ToggleCase,
412        DisableBreakpoint,
413        EnableBreakpoint,
414        EditLogBreakpoint,
415        DebuggerRunToCursor,
416        DebuggerEvaluateSelectedText,
417        ToggleAutoSignatureHelp,
418        ToggleGitBlameInline,
419        OpenGitBlameCommit,
420        ToggleIndentGuides,
421        ToggleInlayHints,
422        ToggleInlineValues,
423        ToggleInlineDiagnostics,
424        ToggleEditPrediction,
425        ToggleLineNumbers,
426        SwapSelectionEnds,
427        SetMark,
428        ToggleRelativeLineNumbers,
429        ToggleSelectionMenu,
430        ToggleSoftWrap,
431        ToggleTabBar,
432        Transpose,
433        Undo,
434        UndoSelection,
435        UnfoldAll,
436        UnfoldLines,
437        UnfoldRecursive,
438        UniqueLinesCaseInsensitive,
439        UniqueLinesCaseSensitive,
440    ]
441);
442
443action_as!(go_to_line, ToggleGoToLine as Toggle);
444
445action_with_deprecated_aliases!(editor, OpenSelectedFilename, ["editor::OpenFile"]);
446action_with_deprecated_aliases!(editor, ToggleSelectedDiffHunks, ["editor::ToggleHunkDiff"]);
447action_with_deprecated_aliases!(editor, ExpandAllDiffHunks, ["editor::ExpandAllHunkDiffs"]);