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