Skip to main content

fresh/input/
commands.rs

1//! Command palette system for executing editor actions by name
2
3use crate::input::keybindings::{Action, KeyContext};
4use crate::types::context_keys;
5use rust_i18n::t;
6
7/// Source of a command (builtin or from a plugin)
8#[derive(Debug, Clone, PartialEq)]
9pub enum CommandSource {
10    /// Built-in editor command
11    Builtin,
12    /// Command registered by a plugin (contains plugin filename without extension)
13    Plugin(String),
14}
15
16/// A command that can be executed from the command palette
17#[derive(Debug, Clone)]
18pub struct Command {
19    /// Command name (e.g., "Open File")
20    pub name: String,
21    /// Command description
22    pub description: String,
23    /// The action to trigger
24    pub action: Action,
25    /// Contexts where this command is available (empty = available in all contexts)
26    pub contexts: Vec<KeyContext>,
27    /// Custom contexts required for this command (plugin-defined contexts like "config-editor")
28    /// If non-empty, all custom contexts must be active for the command to be available
29    pub custom_contexts: Vec<String>,
30    /// Source of the command (builtin or plugin)
31    pub source: CommandSource,
32    /// When `true`, a key bound to this command bypasses terminal
33    /// keyboard capture: the action fires even while a terminal pane
34    /// owns the keyboard. Plugins set this via
35    /// `editor.registerCommand(..., { terminalBypass: true })` so
36    /// commands the user must always reach (orchestrator picker /
37    /// new-session form / panic-exit) aren't trapped by a focused
38    /// PTY. Built-in editor commands like `CommandPalette` rely on
39    /// `KeybindingResolver::is_terminal_ui_action` instead, so the
40    /// flag stays `false` for them and they still bypass the
41    /// existing way.
42    pub terminal_bypass: bool,
43}
44
45impl Command {
46    /// Get the localized name of the command
47    pub fn get_localized_name(&self) -> String {
48        if self.name.starts_with('%') {
49            if let CommandSource::Plugin(ref plugin_name) = self.source {
50                return crate::i18n::translate_plugin_string(
51                    plugin_name,
52                    &self.name[1..],
53                    &std::collections::HashMap::new(),
54                );
55            }
56        }
57        self.name.clone()
58    }
59
60    /// Get the localized description of the command
61    pub fn get_localized_description(&self) -> String {
62        if self.description.starts_with('%') {
63            if let CommandSource::Plugin(ref plugin_name) = self.source {
64                return crate::i18n::translate_plugin_string(
65                    plugin_name,
66                    &self.description[1..],
67                    &std::collections::HashMap::new(),
68                );
69            }
70        }
71        self.description.clone()
72    }
73}
74
75/// A single suggestion item for autocomplete
76#[derive(Debug, Clone, PartialEq)]
77pub struct Suggestion {
78    /// The text to display
79    pub text: String,
80    /// Optional description
81    pub description: Option<String>,
82    /// Optional styled rendering of `description`. When present, these
83    /// spans are rendered (in order) instead of the plain `description`
84    /// string, letting a suggestion highlight part of its row (e.g. the
85    /// symbol word inside a code-line snippet).
86    pub description_spans: Option<Vec<fresh_core::api::StyledText>>,
87    /// The value to use when selected (defaults to text if None)
88    pub value: Option<String>,
89    /// Whether this suggestion is disabled (greyed out)
90    pub disabled: bool,
91    /// Optional keyboard shortcut
92    pub keybinding: Option<String>,
93    /// Source of the command (for command palette)
94    pub source: Option<CommandSource>,
95}
96
97impl Suggestion {
98    /// Create an active (selectable) suggestion
99    pub fn new(text: String) -> Self {
100        Self {
101            text,
102            description: None,
103            description_spans: None,
104            value: None,
105            disabled: false,
106            keybinding: None,
107            source: None,
108        }
109    }
110
111    /// Create a disabled (greyed-out) suggestion used for hints or errors
112    pub fn disabled(text: String) -> Self {
113        Self {
114            text,
115            description: None,
116            description_spans: None,
117            value: None,
118            disabled: true,
119            keybinding: None,
120            source: None,
121        }
122    }
123
124    pub fn with_description(mut self, description: String) -> Self {
125        self.description = Some(description);
126        self
127    }
128
129    pub fn with_description_spans(
130        mut self,
131        spans: Option<Vec<fresh_core::api::StyledText>>,
132    ) -> Self {
133        self.description_spans = spans;
134        self
135    }
136
137    pub fn with_value(mut self, value: String) -> Self {
138        self.value = Some(value);
139        self
140    }
141
142    pub fn with_keybinding(mut self, keybinding: Option<String>) -> Self {
143        self.keybinding = keybinding;
144        self
145    }
146
147    pub fn with_source(mut self, source: Option<CommandSource>) -> Self {
148        self.source = source;
149        self
150    }
151
152    pub fn set_disabled(mut self, disabled: bool) -> Self {
153        self.disabled = disabled;
154        self
155    }
156
157    pub fn get_value(&self) -> &str {
158        self.value.as_ref().unwrap_or(&self.text)
159    }
160}
161
162/// Static definition of a builtin command (all data except translated strings)
163struct CommandDef {
164    name_key: &'static str,
165    desc_key: &'static str,
166    action: fn() -> Action,
167    contexts: &'static [KeyContext],
168    custom_contexts: &'static [&'static str],
169}
170
171use KeyContext::{CompositeBuffer, Dock, FileExplorer, Normal, Terminal};
172
173/// All builtin command definitions as static data.
174/// Translation happens at runtime via the loop in get_all_commands().
175static COMMAND_DEFS: &[CommandDef] = &[
176    // File operations
177    CommandDef {
178        name_key: "cmd.open_file",
179        desc_key: "cmd.open_file_desc",
180        action: || Action::Open,
181        contexts: &[],
182        custom_contexts: &[],
183    },
184    CommandDef {
185        name_key: "cmd.switch_project",
186        desc_key: "cmd.switch_project_desc",
187        action: || Action::SwitchProject,
188        contexts: &[],
189        custom_contexts: &[],
190    },
191    CommandDef {
192        name_key: "cmd.save_file",
193        desc_key: "cmd.save_file_desc",
194        action: || Action::Save,
195        contexts: &[Normal],
196        custom_contexts: &[],
197    },
198    CommandDef {
199        name_key: "cmd.save_file_as",
200        desc_key: "cmd.save_file_as_desc",
201        action: || Action::SaveAs,
202        contexts: &[Normal],
203        custom_contexts: &[],
204    },
205    CommandDef {
206        name_key: "cmd.new_file",
207        desc_key: "cmd.new_file_desc",
208        action: || Action::New,
209        contexts: &[],
210        custom_contexts: &[],
211    },
212    CommandDef {
213        name_key: "cmd.close_buffer",
214        desc_key: "cmd.close_buffer_desc",
215        action: || Action::Close,
216        contexts: &[Normal, Terminal],
217        custom_contexts: &[],
218    },
219    CommandDef {
220        name_key: "cmd.close_tab",
221        desc_key: "cmd.close_tab_desc",
222        action: || Action::CloseTab,
223        contexts: &[Normal, Terminal],
224        custom_contexts: &[],
225    },
226    CommandDef {
227        name_key: "cmd.revert_file",
228        desc_key: "cmd.revert_file_desc",
229        action: || Action::Revert,
230        contexts: &[Normal],
231        custom_contexts: &[],
232    },
233    CommandDef {
234        name_key: "cmd.toggle_auto_revert",
235        desc_key: "cmd.toggle_auto_revert_desc",
236        action: || Action::ToggleAutoRevert,
237        contexts: &[],
238        custom_contexts: &[],
239    },
240    CommandDef {
241        name_key: "cmd.format_buffer",
242        desc_key: "cmd.format_buffer_desc",
243        action: || Action::FormatBuffer,
244        contexts: &[Normal],
245        custom_contexts: &[],
246    },
247    CommandDef {
248        name_key: "cmd.trim_trailing_whitespace",
249        desc_key: "cmd.trim_trailing_whitespace_desc",
250        action: || Action::TrimTrailingWhitespace,
251        contexts: &[Normal],
252        custom_contexts: &[],
253    },
254    CommandDef {
255        name_key: "cmd.ensure_final_newline",
256        desc_key: "cmd.ensure_final_newline_desc",
257        action: || Action::EnsureFinalNewline,
258        contexts: &[Normal],
259        custom_contexts: &[],
260    },
261    CommandDef {
262        name_key: "cmd.quit",
263        desc_key: "cmd.quit_desc",
264        action: || Action::Quit,
265        contexts: &[],
266        custom_contexts: &[],
267    },
268    CommandDef {
269        name_key: "cmd.detach",
270        desc_key: "cmd.detach_desc",
271        action: || Action::Detach,
272        contexts: &[],
273        custom_contexts: &[context_keys::SESSION_MODE],
274    },
275    // Quick Open variants
276    CommandDef {
277        name_key: "cmd.quick_open_buffers",
278        desc_key: "cmd.quick_open_buffers_desc",
279        action: || Action::QuickOpenBuffers,
280        contexts: &[],
281        custom_contexts: &[],
282    },
283    CommandDef {
284        name_key: "cmd.quick_open_files",
285        desc_key: "cmd.quick_open_files_desc",
286        action: || Action::QuickOpenFiles,
287        contexts: &[],
288        custom_contexts: &[],
289    },
290    // Edit operations
291    CommandDef {
292        name_key: "cmd.undo",
293        desc_key: "cmd.undo_desc",
294        action: || Action::Undo,
295        contexts: &[Normal],
296        custom_contexts: &[],
297    },
298    CommandDef {
299        name_key: "cmd.redo",
300        desc_key: "cmd.redo_desc",
301        action: || Action::Redo,
302        contexts: &[Normal],
303        custom_contexts: &[],
304    },
305    CommandDef {
306        name_key: "cmd.copy",
307        desc_key: "cmd.copy_desc",
308        action: || Action::Copy,
309        contexts: &[Normal],
310        custom_contexts: &[],
311    },
312    CommandDef {
313        name_key: "cmd.copy_with_formatting",
314        desc_key: "cmd.copy_with_formatting_desc",
315        action: || Action::CopyWithTheme(String::new()),
316        contexts: &[Normal],
317        custom_contexts: &[],
318    },
319    CommandDef {
320        name_key: "cmd.copy_file_path",
321        desc_key: "cmd.copy_file_path_desc",
322        action: || Action::CopyFilePath,
323        contexts: &[Normal],
324        custom_contexts: &[],
325    },
326    CommandDef {
327        name_key: "cmd.copy_relative_file_path",
328        desc_key: "cmd.copy_relative_file_path_desc",
329        action: || Action::CopyRelativeFilePath,
330        contexts: &[Normal],
331        custom_contexts: &[],
332    },
333    CommandDef {
334        name_key: "cmd.cut",
335        desc_key: "cmd.cut_desc",
336        action: || Action::Cut,
337        contexts: &[Normal],
338        custom_contexts: &[],
339    },
340    CommandDef {
341        name_key: "cmd.paste",
342        desc_key: "cmd.paste_desc",
343        action: || Action::Paste,
344        contexts: &[Normal],
345        custom_contexts: &[],
346    },
347    CommandDef {
348        name_key: "cmd.delete_line",
349        desc_key: "cmd.delete_line_desc",
350        action: || Action::DeleteLine,
351        contexts: &[Normal],
352        custom_contexts: &[],
353    },
354    CommandDef {
355        name_key: "cmd.delete_word_backward",
356        desc_key: "cmd.delete_word_backward_desc",
357        action: || Action::DeleteWordBackward,
358        contexts: &[Normal],
359        custom_contexts: &[],
360    },
361    CommandDef {
362        name_key: "cmd.delete_word_forward",
363        desc_key: "cmd.delete_word_forward_desc",
364        action: || Action::DeleteWordForward,
365        contexts: &[Normal],
366        custom_contexts: &[],
367    },
368    CommandDef {
369        name_key: "cmd.delete_to_end_of_line",
370        desc_key: "cmd.delete_to_end_of_line_desc",
371        action: || Action::DeleteToLineEnd,
372        contexts: &[Normal],
373        custom_contexts: &[],
374    },
375    CommandDef {
376        name_key: "cmd.transpose_characters",
377        desc_key: "cmd.transpose_characters_desc",
378        action: || Action::TransposeChars,
379        contexts: &[Normal],
380        custom_contexts: &[],
381    },
382    CommandDef {
383        name_key: "cmd.transform_uppercase",
384        desc_key: "cmd.transform_uppercase_desc",
385        action: || Action::ToUpperCase,
386        contexts: &[Normal],
387        custom_contexts: &[],
388    },
389    CommandDef {
390        name_key: "cmd.transform_lowercase",
391        desc_key: "cmd.transform_lowercase_desc",
392        action: || Action::ToLowerCase,
393        contexts: &[Normal],
394        custom_contexts: &[],
395    },
396    CommandDef {
397        name_key: "cmd.sort_lines",
398        desc_key: "cmd.sort_lines_desc",
399        action: || Action::SortLines,
400        contexts: &[Normal],
401        custom_contexts: &[],
402    },
403    CommandDef {
404        name_key: "cmd.open_line",
405        desc_key: "cmd.open_line_desc",
406        action: || Action::OpenLine,
407        contexts: &[Normal],
408        custom_contexts: &[],
409    },
410    CommandDef {
411        name_key: "cmd.duplicate_line",
412        desc_key: "cmd.duplicate_line_desc",
413        action: || Action::DuplicateLine,
414        contexts: &[Normal],
415        custom_contexts: &[],
416    },
417    CommandDef {
418        name_key: "cmd.recenter",
419        desc_key: "cmd.recenter_desc",
420        action: || Action::Recenter,
421        contexts: &[Normal],
422        custom_contexts: &[],
423    },
424    CommandDef {
425        name_key: "cmd.set_mark",
426        desc_key: "cmd.set_mark_desc",
427        action: || Action::SetMark,
428        contexts: &[Normal],
429        custom_contexts: &[],
430    },
431    CommandDef {
432        name_key: "cmd.cancel_mark",
433        desc_key: "cmd.cancel_mark_desc",
434        action: || Action::CancelMark,
435        contexts: &[Normal],
436        custom_contexts: &[],
437    },
438    CommandDef {
439        name_key: "cmd.clear_mark",
440        desc_key: "cmd.clear_mark_desc",
441        action: || Action::ClearMark,
442        contexts: &[Normal],
443        custom_contexts: &[],
444    },
445    // Selection
446    CommandDef {
447        name_key: "cmd.select_all",
448        desc_key: "cmd.select_all_desc",
449        action: || Action::SelectAll,
450        contexts: &[Normal],
451        custom_contexts: &[],
452    },
453    CommandDef {
454        name_key: "cmd.select_word",
455        desc_key: "cmd.select_word_desc",
456        action: || Action::SelectWord,
457        contexts: &[Normal],
458        custom_contexts: &[],
459    },
460    CommandDef {
461        name_key: "cmd.select_line",
462        desc_key: "cmd.select_line_desc",
463        action: || Action::SelectLine,
464        contexts: &[Normal],
465        custom_contexts: &[],
466    },
467    CommandDef {
468        name_key: "cmd.expand_selection",
469        desc_key: "cmd.expand_selection_desc",
470        action: || Action::ExpandSelection,
471        contexts: &[Normal],
472        custom_contexts: &[],
473    },
474    // Multi-cursor
475    CommandDef {
476        name_key: "cmd.add_cursor_above",
477        desc_key: "cmd.add_cursor_above_desc",
478        action: || Action::AddCursorAbove,
479        contexts: &[Normal],
480        custom_contexts: &[],
481    },
482    CommandDef {
483        name_key: "cmd.add_cursor_below",
484        desc_key: "cmd.add_cursor_below_desc",
485        action: || Action::AddCursorBelow,
486        contexts: &[Normal],
487        custom_contexts: &[],
488    },
489    CommandDef {
490        name_key: "cmd.add_cursor_next_match",
491        desc_key: "cmd.add_cursor_next_match_desc",
492        action: || Action::AddCursorNextMatch,
493        contexts: &[Normal],
494        custom_contexts: &[],
495    },
496    CommandDef {
497        name_key: "cmd.add_cursors_to_line_ends",
498        desc_key: "cmd.add_cursors_to_line_ends_desc",
499        action: || Action::AddCursorsToLineEnds,
500        contexts: &[Normal],
501        custom_contexts: &[],
502    },
503    CommandDef {
504        name_key: "cmd.remove_secondary_cursors",
505        desc_key: "cmd.remove_secondary_cursors_desc",
506        action: || Action::RemoveSecondaryCursors,
507        contexts: &[Normal],
508        custom_contexts: &[],
509    },
510    // Buffer navigation
511    CommandDef {
512        name_key: "cmd.next_buffer",
513        desc_key: "cmd.next_buffer_desc",
514        action: || Action::NextBuffer,
515        contexts: &[Normal, Terminal],
516        custom_contexts: &[],
517    },
518    CommandDef {
519        name_key: "cmd.previous_buffer",
520        desc_key: "cmd.previous_buffer_desc",
521        action: || Action::PrevBuffer,
522        contexts: &[Normal, Terminal],
523        custom_contexts: &[],
524    },
525    CommandDef {
526        name_key: "cmd.switch_to_previous_tab",
527        desc_key: "cmd.switch_to_previous_tab_desc",
528        action: || Action::SwitchToPreviousTab,
529        contexts: &[Normal, Terminal],
530        custom_contexts: &[],
531    },
532    CommandDef {
533        name_key: "cmd.switch_to_tab_by_name",
534        desc_key: "cmd.switch_to_tab_by_name_desc",
535        action: || Action::SwitchToTabByName,
536        contexts: &[Normal, Terminal],
537        custom_contexts: &[],
538    },
539    // Split operations
540    CommandDef {
541        name_key: "cmd.split_horizontal",
542        desc_key: "cmd.split_horizontal_desc",
543        action: || Action::SplitHorizontal,
544        contexts: &[Normal, Terminal],
545        custom_contexts: &[],
546    },
547    CommandDef {
548        name_key: "cmd.split_vertical",
549        desc_key: "cmd.split_vertical_desc",
550        action: || Action::SplitVertical,
551        contexts: &[Normal, Terminal],
552        custom_contexts: &[],
553    },
554    CommandDef {
555        name_key: "cmd.close_split",
556        desc_key: "cmd.close_split_desc",
557        action: || Action::CloseSplit,
558        contexts: &[Normal, Terminal],
559        custom_contexts: &[],
560    },
561    CommandDef {
562        name_key: "cmd.next_split",
563        desc_key: "cmd.next_split_desc",
564        action: || Action::NextSplit,
565        contexts: &[Normal, Terminal],
566        custom_contexts: &[],
567    },
568    CommandDef {
569        name_key: "cmd.previous_split",
570        desc_key: "cmd.previous_split_desc",
571        action: || Action::PrevSplit,
572        contexts: &[Normal, Terminal],
573        custom_contexts: &[],
574    },
575    CommandDef {
576        name_key: "cmd.next_window",
577        desc_key: "cmd.next_window_desc",
578        action: || Action::NextWindow,
579        contexts: &[],
580        custom_contexts: &[],
581    },
582    CommandDef {
583        name_key: "cmd.previous_window",
584        desc_key: "cmd.previous_window_desc",
585        action: || Action::PrevWindow,
586        contexts: &[],
587        custom_contexts: &[],
588    },
589    CommandDef {
590        name_key: "cmd.increase_split_size",
591        desc_key: "cmd.increase_split_size_desc",
592        action: || Action::IncreaseSplitSize,
593        contexts: &[Normal, Terminal],
594        custom_contexts: &[],
595    },
596    CommandDef {
597        name_key: "cmd.decrease_split_size",
598        desc_key: "cmd.decrease_split_size_desc",
599        action: || Action::DecreaseSplitSize,
600        contexts: &[Normal, Terminal],
601        custom_contexts: &[],
602    },
603    CommandDef {
604        name_key: "cmd.toggle_maximize_split",
605        desc_key: "cmd.toggle_maximize_split_desc",
606        action: || Action::ToggleMaximizeSplit,
607        contexts: &[Normal, Terminal],
608        custom_contexts: &[],
609    },
610    // View toggles
611    CommandDef {
612        name_key: "cmd.toggle_line_numbers",
613        desc_key: "cmd.toggle_line_numbers_desc",
614        action: || Action::ToggleLineNumbers,
615        contexts: &[Normal],
616        custom_contexts: &[],
617    },
618    CommandDef {
619        name_key: "cmd.wave_animation",
620        desc_key: "cmd.wave_animation_desc",
621        action: || Action::TriggerWaveAnimation,
622        contexts: &[Normal],
623        custom_contexts: &[],
624    },
625    CommandDef {
626        name_key: "cmd.toggle_scroll_sync",
627        desc_key: "cmd.toggle_scroll_sync_desc",
628        action: || Action::ToggleScrollSync,
629        contexts: &[Normal],
630        custom_contexts: &[],
631    },
632    CommandDef {
633        name_key: "cmd.toggle_fold",
634        desc_key: "cmd.toggle_fold_desc",
635        action: || Action::ToggleFold,
636        contexts: &[Normal],
637        custom_contexts: &[],
638    },
639    CommandDef {
640        name_key: "cmd.debug_toggle_highlight",
641        desc_key: "cmd.debug_toggle_highlight_desc",
642        action: || Action::ToggleDebugHighlights,
643        contexts: &[Normal],
644        custom_contexts: &[],
645    },
646    // Rulers
647    CommandDef {
648        name_key: "cmd.add_ruler",
649        desc_key: "cmd.add_ruler_desc",
650        action: || Action::AddRuler,
651        contexts: &[Normal],
652        custom_contexts: &[],
653    },
654    CommandDef {
655        name_key: "cmd.remove_ruler",
656        desc_key: "cmd.remove_ruler_desc",
657        action: || Action::RemoveRuler,
658        contexts: &[Normal],
659        custom_contexts: &[],
660    },
661    // Buffer settings
662    CommandDef {
663        name_key: "cmd.set_tab_size",
664        desc_key: "cmd.set_tab_size_desc",
665        action: || Action::SetTabSize,
666        contexts: &[Normal],
667        custom_contexts: &[],
668    },
669    CommandDef {
670        name_key: "cmd.set_line_ending",
671        desc_key: "cmd.set_line_ending_desc",
672        action: || Action::SetLineEnding,
673        contexts: &[Normal],
674        custom_contexts: &[],
675    },
676    CommandDef {
677        name_key: "cmd.set_encoding",
678        desc_key: "cmd.set_encoding_desc",
679        action: || Action::SetEncoding,
680        contexts: &[Normal],
681        custom_contexts: &[],
682    },
683    CommandDef {
684        name_key: "cmd.reload_with_encoding",
685        desc_key: "cmd.reload_with_encoding_desc",
686        action: || Action::ReloadWithEncoding,
687        contexts: &[Normal],
688        custom_contexts: &[],
689    },
690    CommandDef {
691        name_key: "cmd.set_language",
692        desc_key: "cmd.set_language_desc",
693        action: || Action::SetLanguage,
694        contexts: &[Normal],
695        custom_contexts: &[],
696    },
697    CommandDef {
698        name_key: "cmd.toggle_indentation",
699        desc_key: "cmd.toggle_indentation_desc",
700        action: || Action::ToggleIndentationStyle,
701        contexts: &[Normal],
702        custom_contexts: &[],
703    },
704    CommandDef {
705        name_key: "cmd.toggle_tab_indicators",
706        desc_key: "cmd.toggle_tab_indicators_desc",
707        action: || Action::ToggleTabIndicators,
708        contexts: &[Normal],
709        custom_contexts: &[],
710    },
711    CommandDef {
712        name_key: "cmd.toggle_whitespace_indicators",
713        desc_key: "cmd.toggle_whitespace_indicators_desc",
714        action: || Action::ToggleWhitespaceIndicators,
715        contexts: &[Normal],
716        custom_contexts: &[],
717    },
718    CommandDef {
719        name_key: "cmd.reset_buffer_settings",
720        desc_key: "cmd.reset_buffer_settings_desc",
721        action: || Action::ResetBufferSettings,
722        contexts: &[Normal],
723        custom_contexts: &[],
724    },
725    CommandDef {
726        name_key: "cmd.scroll_up",
727        desc_key: "cmd.scroll_up_desc",
728        action: || Action::ScrollUp,
729        contexts: &[Normal],
730        custom_contexts: &[],
731    },
732    CommandDef {
733        name_key: "cmd.scroll_down",
734        desc_key: "cmd.scroll_down_desc",
735        action: || Action::ScrollDown,
736        contexts: &[Normal],
737        custom_contexts: &[],
738    },
739    CommandDef {
740        name_key: "cmd.scroll_tabs_left",
741        desc_key: "cmd.scroll_tabs_left_desc",
742        action: || Action::ScrollTabsLeft,
743        contexts: &[Normal, Terminal],
744        custom_contexts: &[],
745    },
746    CommandDef {
747        name_key: "cmd.scroll_tabs_right",
748        desc_key: "cmd.scroll_tabs_right_desc",
749        action: || Action::ScrollTabsRight,
750        contexts: &[Normal, Terminal],
751        custom_contexts: &[],
752    },
753    CommandDef {
754        name_key: "cmd.toggle_mouse_support",
755        desc_key: "cmd.toggle_mouse_support_desc",
756        action: || Action::ToggleMouseCapture,
757        contexts: &[Normal, Terminal],
758        custom_contexts: &[],
759    },
760    // File explorer
761    CommandDef {
762        name_key: "cmd.toggle_file_explorer",
763        desc_key: "cmd.toggle_file_explorer_desc",
764        action: || Action::ToggleFileExplorer,
765        contexts: &[Normal, FileExplorer, Terminal],
766        custom_contexts: &[],
767    },
768    CommandDef {
769        name_key: "cmd.toggle_file_explorer_side",
770        desc_key: "cmd.toggle_file_explorer_side_desc",
771        action: || Action::ToggleFileExplorerSide,
772        contexts: &[Normal, FileExplorer, Terminal],
773        custom_contexts: &[],
774    },
775    CommandDef {
776        name_key: "cmd.toggle_menu_bar",
777        desc_key: "cmd.toggle_menu_bar_desc",
778        action: || Action::ToggleMenuBar,
779        contexts: &[Normal, FileExplorer, Terminal],
780        custom_contexts: &[],
781    },
782    CommandDef {
783        name_key: "cmd.toggle_tab_bar",
784        desc_key: "cmd.toggle_tab_bar_desc",
785        action: || Action::ToggleTabBar,
786        contexts: &[Normal, FileExplorer, Terminal],
787        custom_contexts: &[],
788    },
789    CommandDef {
790        name_key: "cmd.toggle_status_bar",
791        desc_key: "cmd.toggle_status_bar_desc",
792        action: || Action::ToggleStatusBar,
793        contexts: &[Normal, FileExplorer, Terminal],
794        custom_contexts: &[],
795    },
796    CommandDef {
797        name_key: "cmd.toggle_prompt_line",
798        desc_key: "cmd.toggle_prompt_line_desc",
799        action: || Action::TogglePromptLine,
800        contexts: &[Normal, FileExplorer, Terminal],
801        custom_contexts: &[],
802    },
803    CommandDef {
804        name_key: "cmd.toggle_vertical_scrollbar",
805        desc_key: "cmd.toggle_vertical_scrollbar_desc",
806        action: || Action::ToggleVerticalScrollbar,
807        contexts: &[Normal, FileExplorer, Terminal],
808        custom_contexts: &[],
809    },
810    CommandDef {
811        name_key: "cmd.toggle_horizontal_scrollbar",
812        desc_key: "cmd.toggle_horizontal_scrollbar_desc",
813        action: || Action::ToggleHorizontalScrollbar,
814        contexts: &[Normal, FileExplorer, Terminal],
815        custom_contexts: &[],
816    },
817    CommandDef {
818        name_key: "cmd.focus_file_explorer",
819        desc_key: "cmd.focus_file_explorer_desc",
820        action: || Action::FocusFileExplorer,
821        contexts: &[Normal, Terminal],
822        custom_contexts: &[],
823    },
824    CommandDef {
825        name_key: "cmd.focus_editor",
826        desc_key: "cmd.focus_editor_desc",
827        action: || Action::FocusEditor,
828        contexts: &[FileExplorer],
829        custom_contexts: &[],
830    },
831    CommandDef {
832        name_key: "cmd.toggle_dock_focus",
833        desc_key: "cmd.toggle_dock_focus_desc",
834        action: || Action::ToggleDockFocus,
835        contexts: &[Normal, FileExplorer, Terminal, CompositeBuffer, Dock],
836        custom_contexts: &[],
837    },
838    CommandDef {
839        name_key: "cmd.explorer_refresh",
840        desc_key: "cmd.explorer_refresh_desc",
841        action: || Action::FileExplorerRefresh,
842        contexts: &[FileExplorer],
843        custom_contexts: &[],
844    },
845    CommandDef {
846        name_key: "cmd.explorer_new_file",
847        desc_key: "cmd.explorer_new_file_desc",
848        action: || Action::FileExplorerNewFile,
849        contexts: &[FileExplorer],
850        custom_contexts: &[],
851    },
852    CommandDef {
853        name_key: "cmd.explorer_new_directory",
854        desc_key: "cmd.explorer_new_directory_desc",
855        action: || Action::FileExplorerNewDirectory,
856        contexts: &[FileExplorer],
857        custom_contexts: &[],
858    },
859    CommandDef {
860        name_key: "cmd.explorer_delete",
861        desc_key: "cmd.explorer_delete_desc",
862        action: || Action::FileExplorerDelete,
863        contexts: &[FileExplorer],
864        custom_contexts: &[],
865    },
866    CommandDef {
867        name_key: "cmd.explorer_rename",
868        desc_key: "cmd.explorer_rename_desc",
869        action: || Action::FileExplorerRename,
870        contexts: &[FileExplorer],
871        custom_contexts: &[],
872    },
873    CommandDef {
874        name_key: "cmd.toggle_hidden_files",
875        desc_key: "cmd.toggle_hidden_files_desc",
876        action: || Action::FileExplorerToggleHidden,
877        contexts: &[FileExplorer],
878        custom_contexts: &[],
879    },
880    CommandDef {
881        name_key: "cmd.toggle_gitignored_files",
882        desc_key: "cmd.toggle_gitignored_files_desc",
883        action: || Action::FileExplorerToggleGitignored,
884        contexts: &[FileExplorer],
885        custom_contexts: &[],
886    },
887    // View
888    CommandDef {
889        name_key: "cmd.toggle_line_wrap",
890        desc_key: "cmd.toggle_line_wrap_desc",
891        action: || Action::ToggleLineWrap,
892        contexts: &[Normal],
893        custom_contexts: &[],
894    },
895    CommandDef {
896        name_key: "cmd.toggle_current_line_highlight",
897        desc_key: "cmd.toggle_current_line_highlight_desc",
898        action: || Action::ToggleCurrentLineHighlight,
899        contexts: &[Normal],
900        custom_contexts: &[],
901    },
902    CommandDef {
903        name_key: "cmd.toggle_occurrence_highlight",
904        desc_key: "cmd.toggle_occurrence_highlight_desc",
905        action: || Action::ToggleOccurrenceHighlight,
906        contexts: &[Normal],
907        custom_contexts: &[],
908    },
909    CommandDef {
910        name_key: "cmd.toggle_page_view",
911        desc_key: "cmd.toggle_page_view_desc",
912        action: || Action::TogglePageView,
913        contexts: &[Normal],
914        custom_contexts: &[],
915    },
916    CommandDef {
917        name_key: "cmd.set_page_width",
918        desc_key: "cmd.set_page_width_desc",
919        action: || Action::SetPageWidth,
920        contexts: &[Normal],
921        custom_contexts: &[],
922    },
923    CommandDef {
924        name_key: "cmd.toggle_read_only",
925        desc_key: "cmd.toggle_read_only_desc",
926        action: || Action::ToggleReadOnly,
927        contexts: &[Normal],
928        custom_contexts: &[],
929    },
930    CommandDef {
931        name_key: "cmd.set_background",
932        desc_key: "cmd.set_background_desc",
933        action: || Action::SetBackground,
934        contexts: &[Normal],
935        custom_contexts: &[],
936    },
937    CommandDef {
938        name_key: "cmd.set_background_blend",
939        desc_key: "cmd.set_background_blend_desc",
940        action: || Action::SetBackgroundBlend,
941        contexts: &[Normal],
942        custom_contexts: &[],
943    },
944    // Search and replace
945    CommandDef {
946        name_key: "cmd.search",
947        desc_key: "cmd.search_desc",
948        action: || Action::Search,
949        contexts: &[Normal],
950        custom_contexts: &[],
951    },
952    CommandDef {
953        name_key: "cmd.find_in_selection",
954        desc_key: "cmd.find_in_selection_desc",
955        action: || Action::FindInSelection,
956        contexts: &[Normal],
957        custom_contexts: &[],
958    },
959    CommandDef {
960        name_key: "cmd.find_next",
961        desc_key: "cmd.find_next_desc",
962        action: || Action::FindNext,
963        contexts: &[Normal],
964        custom_contexts: &[],
965    },
966    CommandDef {
967        name_key: "cmd.find_previous",
968        desc_key: "cmd.find_previous_desc",
969        action: || Action::FindPrevious,
970        contexts: &[Normal],
971        custom_contexts: &[],
972    },
973    CommandDef {
974        name_key: "cmd.find_selection_next",
975        desc_key: "cmd.find_selection_next_desc",
976        action: || Action::FindSelectionNext,
977        contexts: &[Normal],
978        custom_contexts: &[],
979    },
980    CommandDef {
981        name_key: "cmd.find_selection_previous",
982        desc_key: "cmd.find_selection_previous_desc",
983        action: || Action::FindSelectionPrevious,
984        contexts: &[Normal],
985        custom_contexts: &[],
986    },
987    CommandDef {
988        name_key: "cmd.clear_search",
989        desc_key: "cmd.clear_search_desc",
990        action: || Action::ClearSearch,
991        contexts: &[Normal],
992        custom_contexts: &[],
993    },
994    CommandDef {
995        name_key: "cmd.replace",
996        desc_key: "cmd.replace_desc",
997        action: || Action::Replace,
998        contexts: &[Normal],
999        custom_contexts: &[],
1000    },
1001    CommandDef {
1002        name_key: "cmd.query_replace",
1003        desc_key: "cmd.query_replace_desc",
1004        action: || Action::QueryReplace,
1005        contexts: &[Normal],
1006        custom_contexts: &[],
1007    },
1008    // Navigation
1009    CommandDef {
1010        name_key: "cmd.goto_line",
1011        desc_key: "cmd.goto_line_desc",
1012        action: || Action::GotoLine,
1013        contexts: &[Normal],
1014        custom_contexts: &[],
1015    },
1016    CommandDef {
1017        name_key: "cmd.scan_line_index",
1018        desc_key: "cmd.scan_line_index_desc",
1019        action: || Action::ScanLineIndex,
1020        contexts: &[Normal],
1021        custom_contexts: &[],
1022    },
1023    CommandDef {
1024        name_key: "cmd.smart_home",
1025        desc_key: "cmd.smart_home_desc",
1026        action: || Action::SmartHome,
1027        contexts: &[Normal],
1028        custom_contexts: &[],
1029    },
1030    CommandDef {
1031        name_key: "cmd.show_completions",
1032        desc_key: "cmd.show_completions_desc",
1033        action: || Action::LspCompletion,
1034        contexts: &[Normal],
1035        custom_contexts: &[],
1036    },
1037    CommandDef {
1038        name_key: "cmd.goto_definition",
1039        desc_key: "cmd.goto_definition_desc",
1040        action: || Action::LspGotoDefinition,
1041        contexts: &[Normal],
1042        custom_contexts: &[],
1043    },
1044    CommandDef {
1045        name_key: "cmd.show_hover_info",
1046        desc_key: "cmd.show_hover_info_desc",
1047        action: || Action::LspHover,
1048        contexts: &[Normal],
1049        custom_contexts: &[],
1050    },
1051    CommandDef {
1052        name_key: "cmd.find_references",
1053        desc_key: "cmd.find_references_desc",
1054        action: || Action::LspReferences,
1055        contexts: &[Normal],
1056        custom_contexts: &[],
1057    },
1058    CommandDef {
1059        name_key: "cmd.show_signature_help",
1060        desc_key: "cmd.show_signature_help_desc",
1061        action: || Action::LspSignatureHelp,
1062        contexts: &[Normal],
1063        custom_contexts: &[],
1064    },
1065    CommandDef {
1066        name_key: "cmd.code_actions",
1067        desc_key: "cmd.code_actions_desc",
1068        action: || Action::LspCodeActions,
1069        contexts: &[Normal],
1070        custom_contexts: &[],
1071    },
1072    CommandDef {
1073        name_key: "cmd.start_restart_lsp",
1074        desc_key: "cmd.start_restart_lsp_desc",
1075        action: || Action::LspRestart,
1076        contexts: &[Normal],
1077        custom_contexts: &[],
1078    },
1079    CommandDef {
1080        name_key: "cmd.stop_lsp",
1081        desc_key: "cmd.stop_lsp_desc",
1082        action: || Action::LspStop,
1083        contexts: &[Normal],
1084        custom_contexts: &[],
1085    },
1086    CommandDef {
1087        name_key: "cmd.toggle_lsp_for_buffer",
1088        desc_key: "cmd.toggle_lsp_for_buffer_desc",
1089        action: || Action::LspToggleForBuffer,
1090        contexts: &[Normal],
1091        custom_contexts: &[],
1092    },
1093    CommandDef {
1094        name_key: "cmd.toggle_mouse_hover",
1095        desc_key: "cmd.toggle_mouse_hover_desc",
1096        action: || Action::ToggleMouseHover,
1097        contexts: &[],
1098        custom_contexts: &[],
1099    },
1100    CommandDef {
1101        name_key: "cmd.navigate_back",
1102        desc_key: "cmd.navigate_back_desc",
1103        action: || Action::NavigateBack,
1104        contexts: &[Normal],
1105        custom_contexts: &[],
1106    },
1107    CommandDef {
1108        name_key: "cmd.navigate_forward",
1109        desc_key: "cmd.navigate_forward_desc",
1110        action: || Action::NavigateForward,
1111        contexts: &[Normal],
1112        custom_contexts: &[],
1113    },
1114    // Smart editing
1115    CommandDef {
1116        name_key: "cmd.toggle_comment",
1117        desc_key: "cmd.toggle_comment_desc",
1118        action: || Action::ToggleComment,
1119        contexts: &[Normal],
1120        custom_contexts: &[],
1121    },
1122    CommandDef {
1123        name_key: "cmd.dedent_selection",
1124        desc_key: "cmd.dedent_selection_desc",
1125        action: || Action::DedentSelection,
1126        contexts: &[Normal],
1127        custom_contexts: &[],
1128    },
1129    CommandDef {
1130        name_key: "cmd.goto_matching_bracket",
1131        desc_key: "cmd.goto_matching_bracket_desc",
1132        action: || Action::GoToMatchingBracket,
1133        contexts: &[Normal],
1134        custom_contexts: &[],
1135    },
1136    // Error navigation
1137    CommandDef {
1138        name_key: "cmd.jump_to_next_error",
1139        desc_key: "cmd.jump_to_next_error_desc",
1140        action: || Action::JumpToNextError,
1141        contexts: &[Normal],
1142        custom_contexts: &[],
1143    },
1144    CommandDef {
1145        name_key: "cmd.jump_to_previous_error",
1146        desc_key: "cmd.jump_to_previous_error_desc",
1147        action: || Action::JumpToPreviousError,
1148        contexts: &[Normal],
1149        custom_contexts: &[],
1150    },
1151    // LSP
1152    CommandDef {
1153        name_key: "cmd.rename_symbol",
1154        desc_key: "cmd.rename_symbol_desc",
1155        action: || Action::LspRename,
1156        contexts: &[Normal],
1157        custom_contexts: &[],
1158    },
1159    // Bookmarks and Macros
1160    CommandDef {
1161        name_key: "cmd.list_bookmarks",
1162        desc_key: "cmd.list_bookmarks_desc",
1163        action: || Action::ListBookmarks,
1164        contexts: &[Normal],
1165        custom_contexts: &[],
1166    },
1167    CommandDef {
1168        name_key: "cmd.list_macros",
1169        desc_key: "cmd.list_macros_desc",
1170        action: || Action::ListMacros,
1171        contexts: &[Normal],
1172        custom_contexts: &[],
1173    },
1174    CommandDef {
1175        name_key: "cmd.record_macro",
1176        desc_key: "cmd.record_macro_desc",
1177        action: || Action::PromptRecordMacro,
1178        contexts: &[Normal],
1179        custom_contexts: &[],
1180    },
1181    CommandDef {
1182        name_key: "cmd.stop_recording_macro",
1183        desc_key: "cmd.stop_recording_macro_desc",
1184        action: || Action::StopMacroRecording,
1185        contexts: &[Normal],
1186        custom_contexts: &[],
1187    },
1188    CommandDef {
1189        name_key: "cmd.play_macro",
1190        desc_key: "cmd.play_macro_desc",
1191        action: || Action::PromptPlayMacro,
1192        contexts: &[Normal],
1193        custom_contexts: &[],
1194    },
1195    CommandDef {
1196        name_key: "cmd.play_last_macro",
1197        desc_key: "cmd.play_last_macro_desc",
1198        action: || Action::PlayLastMacro,
1199        contexts: &[Normal],
1200        custom_contexts: &[],
1201    },
1202    CommandDef {
1203        name_key: "cmd.set_bookmark",
1204        desc_key: "cmd.set_bookmark_desc",
1205        action: || Action::PromptSetBookmark,
1206        contexts: &[Normal],
1207        custom_contexts: &[],
1208    },
1209    CommandDef {
1210        name_key: "cmd.jump_to_bookmark",
1211        desc_key: "cmd.jump_to_bookmark_desc",
1212        action: || Action::PromptJumpToBookmark,
1213        contexts: &[Normal],
1214        custom_contexts: &[],
1215    },
1216    // Help
1217    CommandDef {
1218        name_key: "cmd.show_manual",
1219        desc_key: "cmd.show_manual_desc",
1220        action: || Action::ShowHelp,
1221        contexts: &[],
1222        custom_contexts: &[],
1223    },
1224    CommandDef {
1225        name_key: "cmd.show_keyboard_shortcuts",
1226        desc_key: "cmd.show_keyboard_shortcuts_desc",
1227        action: || Action::ShowKeyboardShortcuts,
1228        contexts: &[],
1229        custom_contexts: &[],
1230    },
1231    CommandDef {
1232        name_key: "cmd.show_warnings",
1233        desc_key: "cmd.show_warnings_desc",
1234        action: || Action::ShowWarnings,
1235        contexts: &[],
1236        custom_contexts: &[],
1237    },
1238    CommandDef {
1239        name_key: "cmd.show_lsp_status",
1240        desc_key: "cmd.show_lsp_status_desc",
1241        action: || Action::ShowLspStatus,
1242        contexts: &[],
1243        custom_contexts: &[],
1244    },
1245    CommandDef {
1246        name_key: "cmd.show_remote_indicator_menu",
1247        desc_key: "cmd.show_remote_indicator_menu_desc",
1248        action: || Action::ShowRemoteIndicatorMenu,
1249        contexts: &[],
1250        custom_contexts: &[],
1251    },
1252    CommandDef {
1253        name_key: "cmd.clear_warnings",
1254        desc_key: "cmd.clear_warnings_desc",
1255        action: || Action::ClearWarnings,
1256        contexts: &[],
1257        custom_contexts: &[],
1258    },
1259    // Config
1260    CommandDef {
1261        name_key: "cmd.dump_config",
1262        desc_key: "cmd.dump_config_desc",
1263        action: || Action::DumpConfig,
1264        contexts: &[],
1265        custom_contexts: &[],
1266    },
1267    CommandDef {
1268        name_key: "cmd.redraw_screen",
1269        desc_key: "cmd.redraw_screen_desc",
1270        action: || Action::RedrawScreen,
1271        contexts: &[],
1272        custom_contexts: &[],
1273    },
1274    CommandDef {
1275        name_key: "cmd.toggle_inlay_hints",
1276        desc_key: "cmd.toggle_inlay_hints_desc",
1277        action: || Action::ToggleInlayHints,
1278        contexts: &[Normal],
1279        custom_contexts: &[],
1280    },
1281    // Theme selection
1282    CommandDef {
1283        name_key: "cmd.select_theme",
1284        desc_key: "cmd.select_theme_desc",
1285        action: || Action::SelectTheme,
1286        contexts: &[],
1287        custom_contexts: &[],
1288    },
1289    // Theme inspection
1290    CommandDef {
1291        name_key: "cmd.inspect_theme_at_cursor",
1292        desc_key: "cmd.inspect_theme_at_cursor_desc",
1293        action: || Action::InspectThemeAtCursor,
1294        contexts: &[Normal],
1295        custom_contexts: &[],
1296    },
1297    // Keybinding map selection
1298    CommandDef {
1299        name_key: "cmd.select_keybinding_map",
1300        desc_key: "cmd.select_keybinding_map_desc",
1301        action: || Action::SelectKeybindingMap,
1302        contexts: &[],
1303        custom_contexts: &[],
1304    },
1305    // Cursor style selection
1306    CommandDef {
1307        name_key: "cmd.select_cursor_style",
1308        desc_key: "cmd.select_cursor_style_desc",
1309        action: || Action::SelectCursorStyle,
1310        contexts: &[],
1311        custom_contexts: &[],
1312    },
1313    // Locale selection
1314    CommandDef {
1315        name_key: "cmd.select_locale",
1316        desc_key: "cmd.select_locale_desc",
1317        action: || Action::SelectLocale,
1318        contexts: &[],
1319        custom_contexts: &[],
1320    },
1321    // Settings
1322    CommandDef {
1323        name_key: "cmd.open_settings",
1324        desc_key: "cmd.open_settings_desc",
1325        action: || Action::OpenSettings,
1326        contexts: &[],
1327        custom_contexts: &[],
1328    },
1329    // Keybinding editor
1330    CommandDef {
1331        name_key: "cmd.open_keybinding_editor",
1332        desc_key: "cmd.open_keybinding_editor_desc",
1333        action: || Action::OpenKeybindingEditor,
1334        contexts: &[],
1335        custom_contexts: &[],
1336    },
1337    // Input calibration
1338    CommandDef {
1339        name_key: "cmd.calibrate_input",
1340        desc_key: "cmd.calibrate_input_desc",
1341        action: || Action::CalibrateInput,
1342        contexts: &[],
1343        custom_contexts: &[],
1344    },
1345    // Terminal commands
1346    CommandDef {
1347        name_key: "cmd.open_terminal",
1348        desc_key: "cmd.open_terminal_desc",
1349        action: || Action::OpenTerminal,
1350        contexts: &[],
1351        custom_contexts: &[],
1352    },
1353    CommandDef {
1354        name_key: "cmd.focus_terminal",
1355        desc_key: "cmd.focus_terminal_desc",
1356        action: || Action::FocusTerminal,
1357        contexts: &[Normal],
1358        custom_contexts: &[],
1359    },
1360    CommandDef {
1361        name_key: "cmd.send_selection_to_terminal",
1362        desc_key: "cmd.send_selection_to_terminal_desc",
1363        action: || Action::SendSelectionToTerminal,
1364        contexts: &[Normal],
1365        custom_contexts: &[],
1366    },
1367    CommandDef {
1368        name_key: "cmd.exit_terminal_mode",
1369        desc_key: "cmd.exit_terminal_mode_desc",
1370        action: || Action::TerminalEscape,
1371        contexts: &[Terminal],
1372        custom_contexts: &[],
1373    },
1374    CommandDef {
1375        name_key: "cmd.toggle_keyboard_capture",
1376        desc_key: "cmd.toggle_keyboard_capture_desc",
1377        action: || Action::ToggleKeyboardCapture,
1378        contexts: &[Terminal],
1379        custom_contexts: &[],
1380    },
1381    // Shell command operations
1382    CommandDef {
1383        name_key: "cmd.shell_command",
1384        desc_key: "cmd.shell_command_desc",
1385        action: || Action::ShellCommand,
1386        contexts: &[Normal],
1387        custom_contexts: &[],
1388    },
1389    CommandDef {
1390        name_key: "cmd.shell_command_replace",
1391        desc_key: "cmd.shell_command_replace_desc",
1392        action: || Action::ShellCommandReplace,
1393        contexts: &[Normal],
1394        custom_contexts: &[],
1395    },
1396    // Debugging
1397    CommandDef {
1398        name_key: "cmd.event_debug",
1399        desc_key: "cmd.event_debug_desc",
1400        action: || Action::EventDebug,
1401        contexts: &[],
1402        custom_contexts: &[],
1403    },
1404    // Process control (Unix job-control suspend)
1405    CommandDef {
1406        name_key: "cmd.suspend_process",
1407        desc_key: "cmd.suspend_process_desc",
1408        action: || Action::SuspendProcess,
1409        contexts: &[Normal, FileExplorer, Terminal],
1410        custom_contexts: &[],
1411    },
1412    // Plugin development
1413    CommandDef {
1414        name_key: "cmd.load_plugin_from_buffer",
1415        desc_key: "cmd.load_plugin_from_buffer_desc",
1416        action: || Action::LoadPluginFromBuffer,
1417        contexts: &[Normal],
1418        custom_contexts: &[],
1419    },
1420    // User init.ts
1421    CommandDef {
1422        name_key: "cmd.init_reload",
1423        desc_key: "cmd.init_reload_desc",
1424        action: || Action::InitReload,
1425        contexts: &[Normal],
1426        custom_contexts: &[],
1427    },
1428    CommandDef {
1429        name_key: "cmd.init_edit",
1430        desc_key: "cmd.init_edit_desc",
1431        action: || Action::InitEdit,
1432        contexts: &[Normal],
1433        custom_contexts: &[],
1434    },
1435    CommandDef {
1436        name_key: "cmd.init_check",
1437        desc_key: "cmd.init_check_desc",
1438        action: || Action::InitCheck,
1439        contexts: &[Normal],
1440        custom_contexts: &[],
1441    },
1442    // Live Grep (issue #1796) — `cmd.live_grep` itself is registered
1443    // by the live_grep plugin (palette title is plugin-controlled);
1444    // these are the editor-side actions that should also be palette-
1445    // discoverable so the user can find them by name.
1446    CommandDef {
1447        name_key: "cmd.resume_live_grep",
1448        desc_key: "cmd.resume_live_grep_desc",
1449        action: || Action::ResumeLiveGrep,
1450        contexts: &[Normal],
1451        custom_contexts: &[],
1452    },
1453    CommandDef {
1454        name_key: "cmd.toggle_utility_dock",
1455        desc_key: "cmd.toggle_utility_dock_desc",
1456        action: || Action::ToggleUtilityDock,
1457        contexts: &[Normal],
1458        custom_contexts: &[],
1459    },
1460    CommandDef {
1461        name_key: "cmd.open_terminal_in_dock",
1462        desc_key: "cmd.open_terminal_in_dock_desc",
1463        action: || Action::OpenTerminalInDock,
1464        contexts: &[Normal],
1465        custom_contexts: &[],
1466    },
1467    // Workspace trust — a single command that opens the trust dialog; the
1468    // dialog itself is where the level is chosen.
1469    CommandDef {
1470        name_key: "cmd.workspace_trust",
1471        desc_key: "cmd.workspace_trust_desc",
1472        action: || Action::WorkspaceTrustPrompt,
1473        contexts: &[],
1474        custom_contexts: &[],
1475    },
1476];
1477
1478/// Get all available commands for the command palette
1479pub fn get_all_commands() -> Vec<Command> {
1480    COMMAND_DEFS
1481        .iter()
1482        .map(|def| Command {
1483            name: t!(def.name_key).to_string(),
1484            description: t!(def.desc_key).to_string(),
1485            action: (def.action)(),
1486            contexts: def.contexts.to_vec(),
1487            custom_contexts: def.custom_contexts.iter().map(|s| s.to_string()).collect(),
1488            source: CommandSource::Builtin,
1489            // Built-in commands use the legacy `is_terminal_ui_action`
1490            // path; the plugin-driven `terminal_bypass` flag isn't
1491            // wired into them.
1492            terminal_bypass: false,
1493        })
1494        .collect()
1495}
1496
1497/// Filter commands by fuzzy matching the query, with context awareness
1498pub fn filter_commands(
1499    query: &str,
1500    current_context: KeyContext,
1501    keybinding_resolver: &crate::input::keybindings::KeybindingResolver,
1502) -> Vec<Suggestion> {
1503    let query_lower = query.to_lowercase();
1504    let commands = get_all_commands();
1505
1506    // Helper function to check if command is available in current context
1507    let is_available = |cmd: &Command| -> bool {
1508        // Empty contexts means available in all contexts
1509        cmd.contexts.is_empty() || cmd.contexts.contains(&current_context)
1510    };
1511
1512    // Helper function for fuzzy matching
1513    let matches_query = |cmd: &Command| -> bool {
1514        if query.is_empty() {
1515            return true;
1516        }
1517
1518        let name_lower = cmd.name.to_lowercase();
1519        let mut query_chars = query_lower.chars();
1520        let mut current_char = query_chars.next();
1521
1522        for name_char in name_lower.chars() {
1523            if let Some(qc) = current_char {
1524                if qc == name_char {
1525                    current_char = query_chars.next();
1526                }
1527            } else {
1528                break;
1529            }
1530        }
1531
1532        current_char.is_none() // All query characters matched
1533    };
1534
1535    // Filter and convert to suggestions
1536    let current_context_ref = &current_context;
1537    let mut suggestions: Vec<Suggestion> = commands
1538        .into_iter()
1539        .filter(|cmd| matches_query(cmd))
1540        .map(|cmd| {
1541            let available = is_available(&cmd);
1542            let keybinding = keybinding_resolver
1543                .get_keybinding_for_action(&cmd.action, current_context_ref.clone());
1544            Suggestion::new(cmd.name.clone())
1545                .with_description(cmd.description)
1546                .set_disabled(!available)
1547                .with_keybinding(keybinding)
1548        })
1549        .collect();
1550
1551    // Sort: available commands first, then disabled ones
1552    suggestions.sort_by_key(|s| s.disabled);
1553
1554    suggestions
1555}