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)]
193#[serde(deny_unknown_fields)]
194pub struct GoToHunk {
195    #[serde(default)]
196    pub center_cursor: bool,
197}
198
199#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
200#[serde(deny_unknown_fields)]
201pub struct GoToPrevHunk {
202    #[serde(default)]
203    pub center_cursor: bool,
204}
205
206#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
207pub struct FoldAtLevel(pub u32);
208
209#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
210#[serde(deny_unknown_fields)]
211pub struct SpawnNearestTask {
212    #[serde(default)]
213    pub reveal: task::RevealStrategy,
214}
215
216#[derive(Debug, PartialEq, Eq, Clone, Copy, Deserialize, Default)]
217pub enum UuidVersion {
218    #[default]
219    V4,
220    V7,
221}
222
223impl_actions!(
224    editor,
225    [
226        ComposeCompletion,
227        ConfirmCodeAction,
228        ConfirmCompletion,
229        DeleteToNextWordEnd,
230        DeleteToPreviousWordStart,
231        ExpandExcerpts,
232        ExpandExcerptsDown,
233        ExpandExcerptsUp,
234        FoldAt,
235        GoToHunk,
236        GoToPrevHunk,
237        HandleInput,
238        MoveDownByLines,
239        MovePageDown,
240        MovePageUp,
241        MoveToBeginningOfLine,
242        MoveToEndOfLine,
243        MoveUpByLines,
244        SelectDownByLines,
245        SelectNext,
246        SelectPrevious,
247        SelectToBeginningOfLine,
248        SelectToEndOfLine,
249        SelectUpByLines,
250        SpawnNearestTask,
251        ShowCompletions,
252        ToggleCodeActions,
253        ToggleComments,
254        UnfoldAt,
255        FoldAtLevel,
256    ]
257);
258
259gpui::actions!(
260    editor,
261    [
262        AcceptEditPrediction,
263        AcceptPartialCopilotSuggestion,
264        AcceptPartialEditPrediction,
265        AddSelectionAbove,
266        AddSelectionBelow,
267        ApplyAllDiffHunks,
268        ApplyDiffHunk,
269        Backspace,
270        Cancel,
271        CancelLanguageServerWork,
272        ConfirmRename,
273        ContextMenuFirst,
274        ContextMenuLast,
275        ContextMenuNext,
276        ContextMenuPrev,
277        ConvertToKebabCase,
278        ConvertToLowerCamelCase,
279        ConvertToLowerCase,
280        ConvertToOppositeCase,
281        ConvertToSnakeCase,
282        ConvertToTitleCase,
283        ConvertToUpperCamelCase,
284        ConvertToUpperCase,
285        Copy,
286        CopyFileLocation,
287        CopyHighlightJson,
288        CopyFileName,
289        CopyFileNameWithoutExtension,
290        CopyPermalinkToLine,
291        Cut,
292        CutToEndOfLine,
293        Delete,
294        DeleteLine,
295        DeleteToBeginningOfLine,
296        DeleteToEndOfLine,
297        DeleteToNextSubwordEnd,
298        DeleteToPreviousSubwordStart,
299        DisplayCursorNames,
300        DuplicateLineDown,
301        DuplicateLineUp,
302        DuplicateSelection,
303        ExpandMacroRecursively,
304        FindAllReferences,
305        Fold,
306        FoldAll,
307        FoldFunctionBodies,
308        FoldRecursive,
309        FoldSelectedRanges,
310        ToggleFold,
311        ToggleFoldRecursive,
312        Format,
313        FormatSelections,
314        GoToDeclaration,
315        GoToDeclarationSplit,
316        GoToDefinition,
317        GoToDefinitionSplit,
318        GoToDiagnostic,
319        GoToImplementation,
320        GoToImplementationSplit,
321        GoToPrevDiagnostic,
322        GoToTypeDefinition,
323        GoToTypeDefinitionSplit,
324        HalfPageDown,
325        HalfPageUp,
326        Hover,
327        Indent,
328        InsertUuidV4,
329        InsertUuidV7,
330        JoinLines,
331        KillRingCut,
332        KillRingYank,
333        LineDown,
334        LineUp,
335        MoveDown,
336        MoveLeft,
337        MoveLineDown,
338        MoveLineUp,
339        MoveRight,
340        MoveToBeginning,
341        MoveToEnclosingBracket,
342        MoveToEnd,
343        MoveToEndOfParagraph,
344        MoveToNextSubwordEnd,
345        MoveToNextWordEnd,
346        MoveToPreviousSubwordStart,
347        MoveToPreviousWordStart,
348        MoveToStartOfParagraph,
349        MoveToStartOfExcerpt,
350        MoveToEndOfExcerpt,
351        MoveUp,
352        Newline,
353        NewlineAbove,
354        NewlineBelow,
355        NextEditPrediction,
356        NextScreen,
357        OpenContextMenu,
358        OpenExcerpts,
359        OpenExcerptsSplit,
360        OpenProposedChangesEditor,
361        OpenDocs,
362        OpenPermalinkToLine,
363        OpenSelectionsInMultibuffer,
364        OpenUrl,
365        OrganizeImports,
366        Outdent,
367        AutoIndent,
368        PageDown,
369        PageUp,
370        Paste,
371        PreviousEditPrediction,
372        Redo,
373        RedoSelection,
374        Rename,
375        RestartLanguageServer,
376        RevealInFileManager,
377        ReverseLines,
378        RevertFile,
379        ReloadFile,
380        Rewrap,
381        ScrollCursorBottom,
382        ScrollCursorCenter,
383        ScrollCursorCenterTopBottom,
384        ScrollCursorTop,
385        SelectAll,
386        SelectAllMatches,
387        SelectToStartOfExcerpt,
388        SelectToEndOfExcerpt,
389        SelectDown,
390        SelectEnclosingSymbol,
391        SelectLargerSyntaxNode,
392        SelectLeft,
393        SelectLine,
394        SelectPageDown,
395        SelectPageUp,
396        SelectRight,
397        SelectSmallerSyntaxNode,
398        SelectToBeginning,
399        SelectToEnd,
400        SelectToEndOfParagraph,
401        SelectToNextSubwordEnd,
402        SelectToNextWordEnd,
403        SelectToPreviousSubwordStart,
404        SelectToPreviousWordStart,
405        SelectToStartOfParagraph,
406        SelectUp,
407        ShowCharacterPalette,
408        ShowEditPrediction,
409        ShowSignatureHelp,
410        ShuffleLines,
411        SortLinesCaseInsensitive,
412        SortLinesCaseSensitive,
413        SplitSelectionIntoLines,
414        SwitchSourceHeader,
415        Tab,
416        TabPrev,
417        ToggleAutoSignatureHelp,
418        ToggleGitBlame,
419        ToggleGitBlameInline,
420        ToggleIndentGuides,
421        ToggleInlayHints,
422        ToggleInlineDiagnostics,
423        ToggleEditPrediction,
424        ToggleLineNumbers,
425        SwapSelectionEnds,
426        SetMark,
427        ToggleRelativeLineNumbers,
428        ToggleSelectionMenu,
429        ToggleSoftWrap,
430        ToggleTabBar,
431        Transpose,
432        Undo,
433        UndoSelection,
434        UnfoldAll,
435        UnfoldLines,
436        UnfoldRecursive,
437        UniqueLinesCaseInsensitive,
438        UniqueLinesCaseSensitive,
439    ]
440);
441
442action_as!(go_to_line, ToggleGoToLine as Toggle);
443
444action_with_deprecated_aliases!(editor, OpenSelectedFilename, ["editor::OpenFile"]);
445action_with_deprecated_aliases!(editor, ToggleSelectedDiffHunks, ["editor::ToggleHunkDiff"]);
446action_with_deprecated_aliases!(editor, ExpandAllDiffHunks, ["editor::ExpandAllHunkDiffs"]);