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