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#[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
251actions!(
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        CopyAndTrim,
279        CopyFileLocation,
280        CopyHighlightJson,
281        CopyFileName,
282        CopyFileNameWithoutExtension,
283        CopyPermalinkToLine,
284        Cut,
285        CutToEndOfLine,
286        Delete,
287        DeleteLine,
288        DeleteToEndOfLine,
289        DeleteToNextSubwordEnd,
290        DeleteToPreviousSubwordStart,
291        DisplayCursorNames,
292        DuplicateLineDown,
293        DuplicateLineUp,
294        DuplicateSelection,
295        ExpandMacroRecursively,
296        FindAllReferences,
297        Fold,
298        FoldAll,
299        FoldFunctionBodies,
300        FoldRecursive,
301        FoldSelectedRanges,
302        ToggleFold,
303        ToggleFoldRecursive,
304        Format,
305        FormatSelections,
306        GoToDeclaration,
307        GoToDeclarationSplit,
308        GoToDefinition,
309        GoToDefinitionSplit,
310        GoToDiagnostic,
311        GoToHunk,
312        GoToPreviousHunk,
313        GoToImplementation,
314        GoToImplementationSplit,
315        GoToPreviousDiagnostic,
316        GoToTypeDefinition,
317        GoToTypeDefinitionSplit,
318        HalfPageDown,
319        HalfPageUp,
320        Hover,
321        Indent,
322        InsertUuidV4,
323        InsertUuidV7,
324        JoinLines,
325        KillRingCut,
326        KillRingYank,
327        LineDown,
328        LineUp,
329        MoveDown,
330        MoveLeft,
331        MoveLineDown,
332        MoveLineUp,
333        MoveRight,
334        MoveToBeginning,
335        MoveToEnclosingBracket,
336        MoveToEnd,
337        MoveToEndOfParagraph,
338        MoveToNextSubwordEnd,
339        MoveToNextWordEnd,
340        MoveToPreviousSubwordStart,
341        MoveToPreviousWordStart,
342        MoveToStartOfParagraph,
343        MoveToStartOfExcerpt,
344        MoveToStartOfNextExcerpt,
345        MoveToEndOfExcerpt,
346        MoveToEndOfPreviousExcerpt,
347        MoveUp,
348        Newline,
349        NewlineAbove,
350        NewlineBelow,
351        NextEditPrediction,
352        NextScreen,
353        OpenContextMenu,
354        OpenExcerpts,
355        OpenExcerptsSplit,
356        OpenProposedChangesEditor,
357        OpenDocs,
358        OpenPermalinkToLine,
359        OpenSelectionsInMultibuffer,
360        OpenUrl,
361        OrganizeImports,
362        Outdent,
363        AutoIndent,
364        PageDown,
365        PageUp,
366        Paste,
367        PreviousEditPrediction,
368        Redo,
369        RedoSelection,
370        Rename,
371        RestartLanguageServer,
372        RevealInFileManager,
373        ReverseLines,
374        RevertFile,
375        ReloadFile,
376        Rewrap,
377        ScrollCursorBottom,
378        ScrollCursorCenter,
379        ScrollCursorCenterTopBottom,
380        ScrollCursorTop,
381        SelectAll,
382        SelectAllMatches,
383        SelectToStartOfExcerpt,
384        SelectToStartOfNextExcerpt,
385        SelectToEndOfExcerpt,
386        SelectToEndOfPreviousExcerpt,
387        SelectDown,
388        SelectEnclosingSymbol,
389        SelectLargerSyntaxNode,
390        SelectLeft,
391        SelectLine,
392        SelectPageDown,
393        SelectPageUp,
394        SelectRight,
395        SelectSmallerSyntaxNode,
396        SelectToBeginning,
397        SelectToEnd,
398        SelectToEndOfParagraph,
399        SelectToNextSubwordEnd,
400        SelectToNextWordEnd,
401        SelectToPreviousSubwordStart,
402        SelectToPreviousWordStart,
403        SelectToStartOfParagraph,
404        SelectUp,
405        ShowCharacterPalette,
406        ShowEditPrediction,
407        ShowSignatureHelp,
408        ShowWordCompletions,
409        ShuffleLines,
410        SortLinesCaseInsensitive,
411        SortLinesCaseSensitive,
412        SplitSelectionIntoLines,
413        SwitchSourceHeader,
414        Tab,
415        Backtab,
416        ToggleBreakpoint,
417        DisableBreakpoint,
418        EnableBreakpoint,
419        EditLogBreakpoint,
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"]);