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