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