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)]
200pub struct FoldAtLevel(pub u32);
201
202#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
203#[serde(deny_unknown_fields)]
204pub struct SpawnNearestTask {
205    #[serde(default)]
206    pub reveal: task::RevealStrategy,
207}
208
209#[derive(Debug, PartialEq, Eq, Clone, Copy, Deserialize, Default)]
210pub enum UuidVersion {
211    #[default]
212    V4,
213    V7,
214}
215
216impl_actions!(
217    editor,
218    [
219        ComposeCompletion,
220        ConfirmCodeAction,
221        ConfirmCompletion,
222        DeleteToBeginningOfLine,
223        DeleteToNextWordEnd,
224        DeleteToPreviousWordStart,
225        ExpandExcerpts,
226        ExpandExcerptsDown,
227        ExpandExcerptsUp,
228        FoldAt,
229        HandleInput,
230        MoveDownByLines,
231        MovePageDown,
232        MovePageUp,
233        MoveToBeginningOfLine,
234        MoveToEndOfLine,
235        MoveUpByLines,
236        SelectDownByLines,
237        SelectNext,
238        SelectPrevious,
239        SelectToBeginningOfLine,
240        SelectToEndOfLine,
241        SelectUpByLines,
242        SpawnNearestTask,
243        ShowCompletions,
244        ToggleCodeActions,
245        ToggleComments,
246        UnfoldAt,
247        FoldAtLevel,
248    ]
249);
250
251gpui::actions!(
252    editor,
253    [
254        AcceptEditPrediction,
255        AcceptPartialCopilotSuggestion,
256        AcceptPartialEditPrediction,
257        AddSelectionAbove,
258        AddSelectionBelow,
259        ApplyAllDiffHunks,
260        ApplyDiffHunk,
261        Backspace,
262        Cancel,
263        CancelLanguageServerWork,
264        ConfirmRename,
265        ContextMenuFirst,
266        ContextMenuLast,
267        ContextMenuNext,
268        ContextMenuPrevious,
269        ConvertToKebabCase,
270        ConvertToLowerCamelCase,
271        ConvertToLowerCase,
272        ConvertToOppositeCase,
273        ConvertToSnakeCase,
274        ConvertToTitleCase,
275        ConvertToUpperCamelCase,
276        ConvertToUpperCase,
277        Copy,
278        CopyFileLocation,
279        CopyHighlightJson,
280        CopyFileName,
281        CopyFileNameWithoutExtension,
282        CopyPermalinkToLine,
283        Cut,
284        CutToEndOfLine,
285        Delete,
286        DeleteLine,
287        DeleteToEndOfLine,
288        DeleteToNextSubwordEnd,
289        DeleteToPreviousSubwordStart,
290        DisplayCursorNames,
291        DuplicateLineDown,
292        DuplicateLineUp,
293        DuplicateSelection,
294        ExpandMacroRecursively,
295        FindAllReferences,
296        Fold,
297        FoldAll,
298        FoldFunctionBodies,
299        FoldRecursive,
300        FoldSelectedRanges,
301        ToggleFold,
302        ToggleFoldRecursive,
303        Format,
304        FormatSelections,
305        GoToDeclaration,
306        GoToDeclarationSplit,
307        GoToDefinition,
308        GoToDefinitionSplit,
309        GoToDiagnostic,
310        GoToHunk,
311        GoToPreviousHunk,
312        GoToImplementation,
313        GoToImplementationSplit,
314        GoToPreviousDiagnostic,
315        GoToTypeDefinition,
316        GoToTypeDefinitionSplit,
317        HalfPageDown,
318        HalfPageUp,
319        Hover,
320        Indent,
321        InsertUuidV4,
322        InsertUuidV7,
323        JoinLines,
324        KillRingCut,
325        KillRingYank,
326        LineDown,
327        LineUp,
328        MoveDown,
329        MoveLeft,
330        MoveLineDown,
331        MoveLineUp,
332        MoveRight,
333        MoveToBeginning,
334        MoveToEnclosingBracket,
335        MoveToEnd,
336        MoveToEndOfParagraph,
337        MoveToNextSubwordEnd,
338        MoveToNextWordEnd,
339        MoveToPreviousSubwordStart,
340        MoveToPreviousWordStart,
341        MoveToStartOfParagraph,
342        MoveToStartOfExcerpt,
343        MoveToEndOfExcerpt,
344        MoveUp,
345        Newline,
346        NewlineAbove,
347        NewlineBelow,
348        NextEditPrediction,
349        NextScreen,
350        OpenContextMenu,
351        OpenExcerpts,
352        OpenExcerptsSplit,
353        OpenProposedChangesEditor,
354        OpenDocs,
355        OpenPermalinkToLine,
356        OpenSelectionsInMultibuffer,
357        OpenUrl,
358        OrganizeImports,
359        Outdent,
360        AutoIndent,
361        PageDown,
362        PageUp,
363        Paste,
364        PreviousEditPrediction,
365        Redo,
366        RedoSelection,
367        Rename,
368        RestartLanguageServer,
369        RevealInFileManager,
370        ReverseLines,
371        RevertFile,
372        ReloadFile,
373        Rewrap,
374        ScrollCursorBottom,
375        ScrollCursorCenter,
376        ScrollCursorCenterTopBottom,
377        ScrollCursorTop,
378        SelectAll,
379        SelectAllMatches,
380        SelectToStartOfExcerpt,
381        SelectToEndOfExcerpt,
382        SelectDown,
383        SelectEnclosingSymbol,
384        SelectLargerSyntaxNode,
385        SelectLeft,
386        SelectLine,
387        SelectPageDown,
388        SelectPageUp,
389        SelectRight,
390        SelectSmallerSyntaxNode,
391        SelectToBeginning,
392        SelectToEnd,
393        SelectToEndOfParagraph,
394        SelectToNextSubwordEnd,
395        SelectToNextWordEnd,
396        SelectToPreviousSubwordStart,
397        SelectToPreviousWordStart,
398        SelectToStartOfParagraph,
399        SelectUp,
400        ShowCharacterPalette,
401        ShowEditPrediction,
402        ShowSignatureHelp,
403        ShuffleLines,
404        SortLinesCaseInsensitive,
405        SortLinesCaseSensitive,
406        SplitSelectionIntoLines,
407        SwitchSourceHeader,
408        Tab,
409        Backtab,
410        ToggleAutoSignatureHelp,
411        ToggleGitBlame,
412        ToggleGitBlameInline,
413        ToggleIndentGuides,
414        ToggleInlayHints,
415        ToggleInlineDiagnostics,
416        ToggleEditPrediction,
417        ToggleLineNumbers,
418        SwapSelectionEnds,
419        SetMark,
420        ToggleRelativeLineNumbers,
421        ToggleSelectionMenu,
422        ToggleSoftWrap,
423        ToggleTabBar,
424        Transpose,
425        Undo,
426        UndoSelection,
427        UnfoldAll,
428        UnfoldLines,
429        UnfoldRecursive,
430        UniqueLinesCaseInsensitive,
431        UniqueLinesCaseSensitive,
432    ]
433);
434
435action_as!(go_to_line, ToggleGoToLine as Toggle);
436
437action_with_deprecated_aliases!(editor, OpenSelectedFilename, ["editor::OpenFile"]);
438action_with_deprecated_aliases!(editor, ToggleSelectedDiffHunks, ["editor::ToggleHunkDiff"]);
439action_with_deprecated_aliases!(editor, ExpandAllDiffHunks, ["editor::ExpandAllHunkDiffs"]);