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