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