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        GoToPreviousDiagnostic,
310        GoToTypeDefinition,
311        GoToTypeDefinitionSplit,
312        HalfPageDown,
313        HalfPageUp,
314        Hover,
315        Indent,
316        InsertUuidV4,
317        InsertUuidV7,
318        JoinLines,
319        KillRingCut,
320        KillRingYank,
321        LineDown,
322        LineUp,
323        MoveDown,
324        MoveLeft,
325        MoveLineDown,
326        MoveLineUp,
327        MoveRight,
328        MoveToBeginning,
329        MoveToEnclosingBracket,
330        MoveToEnd,
331        MoveToEndOfParagraph,
332        MoveToNextSubwordEnd,
333        MoveToNextWordEnd,
334        MoveToPreviousSubwordStart,
335        MoveToPreviousWordStart,
336        MoveToStartOfParagraph,
337        MoveToStartOfExcerpt,
338        MoveToStartOfNextExcerpt,
339        MoveToEndOfExcerpt,
340        MoveToEndOfPreviousExcerpt,
341        MoveUp,
342        Newline,
343        NewlineAbove,
344        NewlineBelow,
345        NextEditPrediction,
346        NextScreen,
347        OpenContextMenu,
348        OpenExcerpts,
349        OpenExcerptsSplit,
350        OpenProposedChangesEditor,
351        OpenDocs,
352        OpenPermalinkToLine,
353        OpenSelectionsInMultibuffer,
354        OpenUrl,
355        OrganizeImports,
356        Outdent,
357        AutoIndent,
358        PageDown,
359        PageUp,
360        Paste,
361        PreviousEditPrediction,
362        Redo,
363        RedoSelection,
364        Rename,
365        RestartLanguageServer,
366        RevealInFileManager,
367        ReverseLines,
368        RevertFile,
369        ReloadFile,
370        Rewrap,
371        ScrollCursorBottom,
372        ScrollCursorCenter,
373        ScrollCursorCenterTopBottom,
374        ScrollCursorTop,
375        SelectAll,
376        SelectAllMatches,
377        SelectToStartOfExcerpt,
378        SelectToStartOfNextExcerpt,
379        SelectToEndOfExcerpt,
380        SelectToEndOfPreviousExcerpt,
381        SelectDown,
382        SelectEnclosingSymbol,
383        SelectLargerSyntaxNode,
384        SelectLeft,
385        SelectLine,
386        SelectPageDown,
387        SelectPageUp,
388        SelectRight,
389        SelectSmallerSyntaxNode,
390        SelectToBeginning,
391        SelectToEnd,
392        SelectToEndOfParagraph,
393        SelectToNextSubwordEnd,
394        SelectToNextWordEnd,
395        SelectToPreviousSubwordStart,
396        SelectToPreviousWordStart,
397        SelectToStartOfParagraph,
398        SelectUp,
399        ShowCharacterPalette,
400        ShowEditPrediction,
401        ShowSignatureHelp,
402        ShowWordCompletions,
403        ShuffleLines,
404        SortLinesCaseInsensitive,
405        SortLinesCaseSensitive,
406        SplitSelectionIntoLines,
407        StopLanguageServer,
408        SwitchSourceHeader,
409        Tab,
410        Backtab,
411        ToggleBreakpoint,
412        ToggleCase,
413        DisableBreakpoint,
414        EnableBreakpoint,
415        EditLogBreakpoint,
416        DebuggerRunToCursor,
417        DebuggerEvaluateSelectedText,
418        ToggleAutoSignatureHelp,
419        ToggleGitBlameInline,
420        OpenGitBlameCommit,
421        ToggleIndentGuides,
422        ToggleInlayHints,
423        ToggleInlineDiagnostics,
424        ToggleEditPrediction,
425        ToggleLineNumbers,
426        SwapSelectionEnds,
427        SetMark,
428        ToggleRelativeLineNumbers,
429        ToggleSelectionMenu,
430        ToggleSoftWrap,
431        ToggleTabBar,
432        Transpose,
433        Undo,
434        UndoSelection,
435        UnfoldAll,
436        UnfoldLines,
437        UnfoldRecursive,
438        UniqueLinesCaseInsensitive,
439        UniqueLinesCaseSensitive,
440    ]
441);
442
443action_as!(go_to_line, ToggleGoToLine as Toggle);
444
445action_with_deprecated_aliases!(editor, OpenSelectedFilename, ["editor::OpenFile"]);
446action_with_deprecated_aliases!(editor, ToggleSelectedDiffHunks, ["editor::ToggleHunkDiff"]);
447action_with_deprecated_aliases!(editor, ExpandAllDiffHunks, ["editor::ExpandAllHunkDiffs"]);