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