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