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        CopyPermalinkToLine,
271        Cut,
272        CutToEndOfLine,
273        Delete,
274        DeleteLine,
275        DeleteToBeginningOfLine,
276        DeleteToEndOfLine,
277        DeleteToNextSubwordEnd,
278        DeleteToPreviousSubwordStart,
279        DisplayCursorNames,
280        DuplicateLineDown,
281        DuplicateLineUp,
282        DuplicateSelection,
283        ExpandMacroRecursively,
284        FindAllReferences,
285        Fold,
286        FoldAll,
287        FoldFunctionBodies,
288        FoldRecursive,
289        FoldSelectedRanges,
290        ToggleFold,
291        ToggleFoldRecursive,
292        Format,
293        FormatSelections,
294        GoToDeclaration,
295        GoToDeclarationSplit,
296        GoToDefinition,
297        GoToDefinitionSplit,
298        GoToDiagnostic,
299        GoToHunk,
300        GoToImplementation,
301        GoToImplementationSplit,
302        GoToPrevDiagnostic,
303        GoToPrevHunk,
304        GoToTypeDefinition,
305        GoToTypeDefinitionSplit,
306        HalfPageDown,
307        HalfPageUp,
308        Hover,
309        Indent,
310        InsertUuidV4,
311        InsertUuidV7,
312        JoinLines,
313        KillRingCut,
314        KillRingYank,
315        LineDown,
316        LineUp,
317        MoveDown,
318        MoveLeft,
319        MoveLineDown,
320        MoveLineUp,
321        MoveRight,
322        MoveToBeginning,
323        MoveToEnclosingBracket,
324        MoveToEnd,
325        MoveToEndOfParagraph,
326        MoveToNextSubwordEnd,
327        MoveToNextWordEnd,
328        MoveToPreviousSubwordStart,
329        MoveToPreviousWordStart,
330        MoveToStartOfParagraph,
331        MoveToStartOfExcerpt,
332        MoveToEndOfExcerpt,
333        MoveUp,
334        Newline,
335        NewlineAbove,
336        NewlineBelow,
337        NextEditPrediction,
338        NextScreen,
339        OpenContextMenu,
340        OpenExcerpts,
341        OpenExcerptsSplit,
342        OpenProposedChangesEditor,
343        OpenDocs,
344        OpenPermalinkToLine,
345        OpenSelectionsInMultibuffer,
346        OpenUrl,
347        Outdent,
348        AutoIndent,
349        PageDown,
350        PageUp,
351        Paste,
352        PreviousEditPrediction,
353        Redo,
354        RedoSelection,
355        Rename,
356        RestartLanguageServer,
357        RevealInFileManager,
358        ReverseLines,
359        RevertFile,
360        ReloadFile,
361        Rewrap,
362        ScrollCursorBottom,
363        ScrollCursorCenter,
364        ScrollCursorCenterTopBottom,
365        ScrollCursorTop,
366        SelectAll,
367        SelectAllMatches,
368        SelectToStartOfExcerpt,
369        SelectToEndOfExcerpt,
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        ToggleInlineDiagnostics,
404        ToggleEditPrediction,
405        ToggleLineNumbers,
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"]);
427action_with_deprecated_aliases!(editor, ExpandAllDiffHunks, ["editor::ExpandAllHunkDiffs"]);