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