actions.rs

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