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    // Selection
432    CommandDef {
433        name_key: "cmd.select_all",
434        desc_key: "cmd.select_all_desc",
435        action: || Action::SelectAll,
436        contexts: &[Normal],
437        custom_contexts: &[],
438    },
439    CommandDef {
440        name_key: "cmd.select_word",
441        desc_key: "cmd.select_word_desc",
442        action: || Action::SelectWord,
443        contexts: &[Normal],
444        custom_contexts: &[],
445    },
446    CommandDef {
447        name_key: "cmd.select_line",
448        desc_key: "cmd.select_line_desc",
449        action: || Action::SelectLine,
450        contexts: &[Normal],
451        custom_contexts: &[],
452    },
453    CommandDef {
454        name_key: "cmd.expand_selection",
455        desc_key: "cmd.expand_selection_desc",
456        action: || Action::ExpandSelection,
457        contexts: &[Normal],
458        custom_contexts: &[],
459    },
460    // Multi-cursor
461    CommandDef {
462        name_key: "cmd.add_cursor_above",
463        desc_key: "cmd.add_cursor_above_desc",
464        action: || Action::AddCursorAbove,
465        contexts: &[Normal],
466        custom_contexts: &[],
467    },
468    CommandDef {
469        name_key: "cmd.add_cursor_below",
470        desc_key: "cmd.add_cursor_below_desc",
471        action: || Action::AddCursorBelow,
472        contexts: &[Normal],
473        custom_contexts: &[],
474    },
475    CommandDef {
476        name_key: "cmd.add_cursor_next_match",
477        desc_key: "cmd.add_cursor_next_match_desc",
478        action: || Action::AddCursorNextMatch,
479        contexts: &[Normal],
480        custom_contexts: &[],
481    },
482    CommandDef {
483        name_key: "cmd.add_cursors_to_line_ends",
484        desc_key: "cmd.add_cursors_to_line_ends_desc",
485        action: || Action::AddCursorsToLineEnds,
486        contexts: &[Normal],
487        custom_contexts: &[],
488    },
489    CommandDef {
490        name_key: "cmd.remove_secondary_cursors",
491        desc_key: "cmd.remove_secondary_cursors_desc",
492        action: || Action::RemoveSecondaryCursors,
493        contexts: &[Normal],
494        custom_contexts: &[],
495    },
496    // Buffer navigation
497    CommandDef {
498        name_key: "cmd.next_buffer",
499        desc_key: "cmd.next_buffer_desc",
500        action: || Action::NextBuffer,
501        contexts: &[Normal, Terminal],
502        custom_contexts: &[],
503    },
504    CommandDef {
505        name_key: "cmd.previous_buffer",
506        desc_key: "cmd.previous_buffer_desc",
507        action: || Action::PrevBuffer,
508        contexts: &[Normal, Terminal],
509        custom_contexts: &[],
510    },
511    CommandDef {
512        name_key: "cmd.switch_to_previous_tab",
513        desc_key: "cmd.switch_to_previous_tab_desc",
514        action: || Action::SwitchToPreviousTab,
515        contexts: &[Normal, Terminal],
516        custom_contexts: &[],
517    },
518    CommandDef {
519        name_key: "cmd.switch_to_tab_by_name",
520        desc_key: "cmd.switch_to_tab_by_name_desc",
521        action: || Action::SwitchToTabByName,
522        contexts: &[Normal, Terminal],
523        custom_contexts: &[],
524    },
525    // Split operations
526    CommandDef {
527        name_key: "cmd.split_horizontal",
528        desc_key: "cmd.split_horizontal_desc",
529        action: || Action::SplitHorizontal,
530        contexts: &[Normal, Terminal],
531        custom_contexts: &[],
532    },
533    CommandDef {
534        name_key: "cmd.split_vertical",
535        desc_key: "cmd.split_vertical_desc",
536        action: || Action::SplitVertical,
537        contexts: &[Normal, Terminal],
538        custom_contexts: &[],
539    },
540    CommandDef {
541        name_key: "cmd.close_split",
542        desc_key: "cmd.close_split_desc",
543        action: || Action::CloseSplit,
544        contexts: &[Normal, Terminal],
545        custom_contexts: &[],
546    },
547    CommandDef {
548        name_key: "cmd.next_split",
549        desc_key: "cmd.next_split_desc",
550        action: || Action::NextSplit,
551        contexts: &[Normal, Terminal],
552        custom_contexts: &[],
553    },
554    CommandDef {
555        name_key: "cmd.previous_split",
556        desc_key: "cmd.previous_split_desc",
557        action: || Action::PrevSplit,
558        contexts: &[Normal, Terminal],
559        custom_contexts: &[],
560    },
561    CommandDef {
562        name_key: "cmd.next_window",
563        desc_key: "cmd.next_window_desc",
564        action: || Action::NextWindow,
565        contexts: &[],
566        custom_contexts: &[],
567    },
568    CommandDef {
569        name_key: "cmd.previous_window",
570        desc_key: "cmd.previous_window_desc",
571        action: || Action::PrevWindow,
572        contexts: &[],
573        custom_contexts: &[],
574    },
575    CommandDef {
576        name_key: "cmd.increase_split_size",
577        desc_key: "cmd.increase_split_size_desc",
578        action: || Action::IncreaseSplitSize,
579        contexts: &[Normal, Terminal],
580        custom_contexts: &[],
581    },
582    CommandDef {
583        name_key: "cmd.decrease_split_size",
584        desc_key: "cmd.decrease_split_size_desc",
585        action: || Action::DecreaseSplitSize,
586        contexts: &[Normal, Terminal],
587        custom_contexts: &[],
588    },
589    CommandDef {
590        name_key: "cmd.toggle_maximize_split",
591        desc_key: "cmd.toggle_maximize_split_desc",
592        action: || Action::ToggleMaximizeSplit,
593        contexts: &[Normal, Terminal],
594        custom_contexts: &[],
595    },
596    // View toggles
597    CommandDef {
598        name_key: "cmd.toggle_line_numbers",
599        desc_key: "cmd.toggle_line_numbers_desc",
600        action: || Action::ToggleLineNumbers,
601        contexts: &[Normal],
602        custom_contexts: &[],
603    },
604    CommandDef {
605        name_key: "cmd.wave_animation",
606        desc_key: "cmd.wave_animation_desc",
607        action: || Action::TriggerWaveAnimation,
608        contexts: &[Normal],
609        custom_contexts: &[],
610    },
611    CommandDef {
612        name_key: "cmd.toggle_scroll_sync",
613        desc_key: "cmd.toggle_scroll_sync_desc",
614        action: || Action::ToggleScrollSync,
615        contexts: &[Normal],
616        custom_contexts: &[],
617    },
618    CommandDef {
619        name_key: "cmd.toggle_fold",
620        desc_key: "cmd.toggle_fold_desc",
621        action: || Action::ToggleFold,
622        contexts: &[Normal],
623        custom_contexts: &[],
624    },
625    CommandDef {
626        name_key: "cmd.debug_toggle_highlight",
627        desc_key: "cmd.debug_toggle_highlight_desc",
628        action: || Action::ToggleDebugHighlights,
629        contexts: &[Normal],
630        custom_contexts: &[],
631    },
632    // Rulers
633    CommandDef {
634        name_key: "cmd.add_ruler",
635        desc_key: "cmd.add_ruler_desc",
636        action: || Action::AddRuler,
637        contexts: &[Normal],
638        custom_contexts: &[],
639    },
640    CommandDef {
641        name_key: "cmd.remove_ruler",
642        desc_key: "cmd.remove_ruler_desc",
643        action: || Action::RemoveRuler,
644        contexts: &[Normal],
645        custom_contexts: &[],
646    },
647    // Buffer settings
648    CommandDef {
649        name_key: "cmd.set_tab_size",
650        desc_key: "cmd.set_tab_size_desc",
651        action: || Action::SetTabSize,
652        contexts: &[Normal],
653        custom_contexts: &[],
654    },
655    CommandDef {
656        name_key: "cmd.set_line_ending",
657        desc_key: "cmd.set_line_ending_desc",
658        action: || Action::SetLineEnding,
659        contexts: &[Normal],
660        custom_contexts: &[],
661    },
662    CommandDef {
663        name_key: "cmd.set_encoding",
664        desc_key: "cmd.set_encoding_desc",
665        action: || Action::SetEncoding,
666        contexts: &[Normal],
667        custom_contexts: &[],
668    },
669    CommandDef {
670        name_key: "cmd.reload_with_encoding",
671        desc_key: "cmd.reload_with_encoding_desc",
672        action: || Action::ReloadWithEncoding,
673        contexts: &[Normal],
674        custom_contexts: &[],
675    },
676    CommandDef {
677        name_key: "cmd.set_language",
678        desc_key: "cmd.set_language_desc",
679        action: || Action::SetLanguage,
680        contexts: &[Normal],
681        custom_contexts: &[],
682    },
683    CommandDef {
684        name_key: "cmd.toggle_indentation",
685        desc_key: "cmd.toggle_indentation_desc",
686        action: || Action::ToggleIndentationStyle,
687        contexts: &[Normal],
688        custom_contexts: &[],
689    },
690    CommandDef {
691        name_key: "cmd.toggle_tab_indicators",
692        desc_key: "cmd.toggle_tab_indicators_desc",
693        action: || Action::ToggleTabIndicators,
694        contexts: &[Normal],
695        custom_contexts: &[],
696    },
697    CommandDef {
698        name_key: "cmd.toggle_whitespace_indicators",
699        desc_key: "cmd.toggle_whitespace_indicators_desc",
700        action: || Action::ToggleWhitespaceIndicators,
701        contexts: &[Normal],
702        custom_contexts: &[],
703    },
704    CommandDef {
705        name_key: "cmd.reset_buffer_settings",
706        desc_key: "cmd.reset_buffer_settings_desc",
707        action: || Action::ResetBufferSettings,
708        contexts: &[Normal],
709        custom_contexts: &[],
710    },
711    CommandDef {
712        name_key: "cmd.scroll_up",
713        desc_key: "cmd.scroll_up_desc",
714        action: || Action::ScrollUp,
715        contexts: &[Normal],
716        custom_contexts: &[],
717    },
718    CommandDef {
719        name_key: "cmd.scroll_down",
720        desc_key: "cmd.scroll_down_desc",
721        action: || Action::ScrollDown,
722        contexts: &[Normal],
723        custom_contexts: &[],
724    },
725    CommandDef {
726        name_key: "cmd.scroll_tabs_left",
727        desc_key: "cmd.scroll_tabs_left_desc",
728        action: || Action::ScrollTabsLeft,
729        contexts: &[Normal, Terminal],
730        custom_contexts: &[],
731    },
732    CommandDef {
733        name_key: "cmd.scroll_tabs_right",
734        desc_key: "cmd.scroll_tabs_right_desc",
735        action: || Action::ScrollTabsRight,
736        contexts: &[Normal, Terminal],
737        custom_contexts: &[],
738    },
739    CommandDef {
740        name_key: "cmd.toggle_mouse_support",
741        desc_key: "cmd.toggle_mouse_support_desc",
742        action: || Action::ToggleMouseCapture,
743        contexts: &[Normal, Terminal],
744        custom_contexts: &[],
745    },
746    // File explorer
747    CommandDef {
748        name_key: "cmd.toggle_file_explorer",
749        desc_key: "cmd.toggle_file_explorer_desc",
750        action: || Action::ToggleFileExplorer,
751        contexts: &[Normal, FileExplorer, Terminal],
752        custom_contexts: &[],
753    },
754    CommandDef {
755        name_key: "cmd.toggle_file_explorer_side",
756        desc_key: "cmd.toggle_file_explorer_side_desc",
757        action: || Action::ToggleFileExplorerSide,
758        contexts: &[Normal, FileExplorer, Terminal],
759        custom_contexts: &[],
760    },
761    CommandDef {
762        name_key: "cmd.toggle_menu_bar",
763        desc_key: "cmd.toggle_menu_bar_desc",
764        action: || Action::ToggleMenuBar,
765        contexts: &[Normal, FileExplorer, Terminal],
766        custom_contexts: &[],
767    },
768    CommandDef {
769        name_key: "cmd.toggle_tab_bar",
770        desc_key: "cmd.toggle_tab_bar_desc",
771        action: || Action::ToggleTabBar,
772        contexts: &[Normal, FileExplorer, Terminal],
773        custom_contexts: &[],
774    },
775    CommandDef {
776        name_key: "cmd.toggle_status_bar",
777        desc_key: "cmd.toggle_status_bar_desc",
778        action: || Action::ToggleStatusBar,
779        contexts: &[Normal, FileExplorer, Terminal],
780        custom_contexts: &[],
781    },
782    CommandDef {
783        name_key: "cmd.toggle_prompt_line",
784        desc_key: "cmd.toggle_prompt_line_desc",
785        action: || Action::TogglePromptLine,
786        contexts: &[Normal, FileExplorer, Terminal],
787        custom_contexts: &[],
788    },
789    CommandDef {
790        name_key: "cmd.toggle_vertical_scrollbar",
791        desc_key: "cmd.toggle_vertical_scrollbar_desc",
792        action: || Action::ToggleVerticalScrollbar,
793        contexts: &[Normal, FileExplorer, Terminal],
794        custom_contexts: &[],
795    },
796    CommandDef {
797        name_key: "cmd.toggle_horizontal_scrollbar",
798        desc_key: "cmd.toggle_horizontal_scrollbar_desc",
799        action: || Action::ToggleHorizontalScrollbar,
800        contexts: &[Normal, FileExplorer, Terminal],
801        custom_contexts: &[],
802    },
803    CommandDef {
804        name_key: "cmd.focus_file_explorer",
805        desc_key: "cmd.focus_file_explorer_desc",
806        action: || Action::FocusFileExplorer,
807        contexts: &[Normal, Terminal],
808        custom_contexts: &[],
809    },
810    CommandDef {
811        name_key: "cmd.focus_editor",
812        desc_key: "cmd.focus_editor_desc",
813        action: || Action::FocusEditor,
814        contexts: &[FileExplorer],
815        custom_contexts: &[],
816    },
817    CommandDef {
818        name_key: "cmd.toggle_dock_focus",
819        desc_key: "cmd.toggle_dock_focus_desc",
820        action: || Action::ToggleDockFocus,
821        contexts: &[Normal, FileExplorer, Terminal, CompositeBuffer, Dock],
822        custom_contexts: &[],
823    },
824    CommandDef {
825        name_key: "cmd.explorer_refresh",
826        desc_key: "cmd.explorer_refresh_desc",
827        action: || Action::FileExplorerRefresh,
828        contexts: &[FileExplorer],
829        custom_contexts: &[],
830    },
831    CommandDef {
832        name_key: "cmd.explorer_new_file",
833        desc_key: "cmd.explorer_new_file_desc",
834        action: || Action::FileExplorerNewFile,
835        contexts: &[FileExplorer],
836        custom_contexts: &[],
837    },
838    CommandDef {
839        name_key: "cmd.explorer_new_directory",
840        desc_key: "cmd.explorer_new_directory_desc",
841        action: || Action::FileExplorerNewDirectory,
842        contexts: &[FileExplorer],
843        custom_contexts: &[],
844    },
845    CommandDef {
846        name_key: "cmd.explorer_delete",
847        desc_key: "cmd.explorer_delete_desc",
848        action: || Action::FileExplorerDelete,
849        contexts: &[FileExplorer],
850        custom_contexts: &[],
851    },
852    CommandDef {
853        name_key: "cmd.explorer_rename",
854        desc_key: "cmd.explorer_rename_desc",
855        action: || Action::FileExplorerRename,
856        contexts: &[FileExplorer],
857        custom_contexts: &[],
858    },
859    CommandDef {
860        name_key: "cmd.toggle_hidden_files",
861        desc_key: "cmd.toggle_hidden_files_desc",
862        action: || Action::FileExplorerToggleHidden,
863        contexts: &[FileExplorer],
864        custom_contexts: &[],
865    },
866    CommandDef {
867        name_key: "cmd.toggle_gitignored_files",
868        desc_key: "cmd.toggle_gitignored_files_desc",
869        action: || Action::FileExplorerToggleGitignored,
870        contexts: &[FileExplorer],
871        custom_contexts: &[],
872    },
873    // View
874    CommandDef {
875        name_key: "cmd.toggle_line_wrap",
876        desc_key: "cmd.toggle_line_wrap_desc",
877        action: || Action::ToggleLineWrap,
878        contexts: &[Normal],
879        custom_contexts: &[],
880    },
881    CommandDef {
882        name_key: "cmd.toggle_current_line_highlight",
883        desc_key: "cmd.toggle_current_line_highlight_desc",
884        action: || Action::ToggleCurrentLineHighlight,
885        contexts: &[Normal],
886        custom_contexts: &[],
887    },
888    CommandDef {
889        name_key: "cmd.toggle_occurrence_highlight",
890        desc_key: "cmd.toggle_occurrence_highlight_desc",
891        action: || Action::ToggleOccurrenceHighlight,
892        contexts: &[Normal],
893        custom_contexts: &[],
894    },
895    CommandDef {
896        name_key: "cmd.toggle_page_view",
897        desc_key: "cmd.toggle_page_view_desc",
898        action: || Action::TogglePageView,
899        contexts: &[Normal],
900        custom_contexts: &[],
901    },
902    CommandDef {
903        name_key: "cmd.set_page_width",
904        desc_key: "cmd.set_page_width_desc",
905        action: || Action::SetPageWidth,
906        contexts: &[Normal],
907        custom_contexts: &[],
908    },
909    CommandDef {
910        name_key: "cmd.toggle_read_only",
911        desc_key: "cmd.toggle_read_only_desc",
912        action: || Action::ToggleReadOnly,
913        contexts: &[Normal],
914        custom_contexts: &[],
915    },
916    CommandDef {
917        name_key: "cmd.set_background",
918        desc_key: "cmd.set_background_desc",
919        action: || Action::SetBackground,
920        contexts: &[Normal],
921        custom_contexts: &[],
922    },
923    CommandDef {
924        name_key: "cmd.set_background_blend",
925        desc_key: "cmd.set_background_blend_desc",
926        action: || Action::SetBackgroundBlend,
927        contexts: &[Normal],
928        custom_contexts: &[],
929    },
930    // Search and replace
931    CommandDef {
932        name_key: "cmd.search",
933        desc_key: "cmd.search_desc",
934        action: || Action::Search,
935        contexts: &[Normal],
936        custom_contexts: &[],
937    },
938    CommandDef {
939        name_key: "cmd.find_in_selection",
940        desc_key: "cmd.find_in_selection_desc",
941        action: || Action::FindInSelection,
942        contexts: &[Normal],
943        custom_contexts: &[],
944    },
945    CommandDef {
946        name_key: "cmd.find_next",
947        desc_key: "cmd.find_next_desc",
948        action: || Action::FindNext,
949        contexts: &[Normal],
950        custom_contexts: &[],
951    },
952    CommandDef {
953        name_key: "cmd.find_previous",
954        desc_key: "cmd.find_previous_desc",
955        action: || Action::FindPrevious,
956        contexts: &[Normal],
957        custom_contexts: &[],
958    },
959    CommandDef {
960        name_key: "cmd.find_selection_next",
961        desc_key: "cmd.find_selection_next_desc",
962        action: || Action::FindSelectionNext,
963        contexts: &[Normal],
964        custom_contexts: &[],
965    },
966    CommandDef {
967        name_key: "cmd.find_selection_previous",
968        desc_key: "cmd.find_selection_previous_desc",
969        action: || Action::FindSelectionPrevious,
970        contexts: &[Normal],
971        custom_contexts: &[],
972    },
973    CommandDef {
974        name_key: "cmd.clear_search",
975        desc_key: "cmd.clear_search_desc",
976        action: || Action::ClearSearch,
977        contexts: &[Normal],
978        custom_contexts: &[],
979    },
980    CommandDef {
981        name_key: "cmd.replace",
982        desc_key: "cmd.replace_desc",
983        action: || Action::Replace,
984        contexts: &[Normal],
985        custom_contexts: &[],
986    },
987    CommandDef {
988        name_key: "cmd.query_replace",
989        desc_key: "cmd.query_replace_desc",
990        action: || Action::QueryReplace,
991        contexts: &[Normal],
992        custom_contexts: &[],
993    },
994    // Navigation
995    CommandDef {
996        name_key: "cmd.goto_line",
997        desc_key: "cmd.goto_line_desc",
998        action: || Action::GotoLine,
999        contexts: &[Normal],
1000        custom_contexts: &[],
1001    },
1002    CommandDef {
1003        name_key: "cmd.scan_line_index",
1004        desc_key: "cmd.scan_line_index_desc",
1005        action: || Action::ScanLineIndex,
1006        contexts: &[Normal],
1007        custom_contexts: &[],
1008    },
1009    CommandDef {
1010        name_key: "cmd.smart_home",
1011        desc_key: "cmd.smart_home_desc",
1012        action: || Action::SmartHome,
1013        contexts: &[Normal],
1014        custom_contexts: &[],
1015    },
1016    CommandDef {
1017        name_key: "cmd.show_completions",
1018        desc_key: "cmd.show_completions_desc",
1019        action: || Action::LspCompletion,
1020        contexts: &[Normal],
1021        custom_contexts: &[],
1022    },
1023    CommandDef {
1024        name_key: "cmd.goto_definition",
1025        desc_key: "cmd.goto_definition_desc",
1026        action: || Action::LspGotoDefinition,
1027        contexts: &[Normal],
1028        custom_contexts: &[],
1029    },
1030    CommandDef {
1031        name_key: "cmd.show_hover_info",
1032        desc_key: "cmd.show_hover_info_desc",
1033        action: || Action::LspHover,
1034        contexts: &[Normal],
1035        custom_contexts: &[],
1036    },
1037    CommandDef {
1038        name_key: "cmd.find_references",
1039        desc_key: "cmd.find_references_desc",
1040        action: || Action::LspReferences,
1041        contexts: &[Normal],
1042        custom_contexts: &[],
1043    },
1044    CommandDef {
1045        name_key: "cmd.show_signature_help",
1046        desc_key: "cmd.show_signature_help_desc",
1047        action: || Action::LspSignatureHelp,
1048        contexts: &[Normal],
1049        custom_contexts: &[],
1050    },
1051    CommandDef {
1052        name_key: "cmd.code_actions",
1053        desc_key: "cmd.code_actions_desc",
1054        action: || Action::LspCodeActions,
1055        contexts: &[Normal],
1056        custom_contexts: &[],
1057    },
1058    CommandDef {
1059        name_key: "cmd.start_restart_lsp",
1060        desc_key: "cmd.start_restart_lsp_desc",
1061        action: || Action::LspRestart,
1062        contexts: &[Normal],
1063        custom_contexts: &[],
1064    },
1065    CommandDef {
1066        name_key: "cmd.stop_lsp",
1067        desc_key: "cmd.stop_lsp_desc",
1068        action: || Action::LspStop,
1069        contexts: &[Normal],
1070        custom_contexts: &[],
1071    },
1072    CommandDef {
1073        name_key: "cmd.toggle_lsp_for_buffer",
1074        desc_key: "cmd.toggle_lsp_for_buffer_desc",
1075        action: || Action::LspToggleForBuffer,
1076        contexts: &[Normal],
1077        custom_contexts: &[],
1078    },
1079    CommandDef {
1080        name_key: "cmd.toggle_mouse_hover",
1081        desc_key: "cmd.toggle_mouse_hover_desc",
1082        action: || Action::ToggleMouseHover,
1083        contexts: &[],
1084        custom_contexts: &[],
1085    },
1086    CommandDef {
1087        name_key: "cmd.navigate_back",
1088        desc_key: "cmd.navigate_back_desc",
1089        action: || Action::NavigateBack,
1090        contexts: &[Normal],
1091        custom_contexts: &[],
1092    },
1093    CommandDef {
1094        name_key: "cmd.navigate_forward",
1095        desc_key: "cmd.navigate_forward_desc",
1096        action: || Action::NavigateForward,
1097        contexts: &[Normal],
1098        custom_contexts: &[],
1099    },
1100    // Smart editing
1101    CommandDef {
1102        name_key: "cmd.toggle_comment",
1103        desc_key: "cmd.toggle_comment_desc",
1104        action: || Action::ToggleComment,
1105        contexts: &[Normal],
1106        custom_contexts: &[],
1107    },
1108    CommandDef {
1109        name_key: "cmd.dedent_selection",
1110        desc_key: "cmd.dedent_selection_desc",
1111        action: || Action::DedentSelection,
1112        contexts: &[Normal],
1113        custom_contexts: &[],
1114    },
1115    CommandDef {
1116        name_key: "cmd.goto_matching_bracket",
1117        desc_key: "cmd.goto_matching_bracket_desc",
1118        action: || Action::GoToMatchingBracket,
1119        contexts: &[Normal],
1120        custom_contexts: &[],
1121    },
1122    // Error navigation
1123    CommandDef {
1124        name_key: "cmd.jump_to_next_error",
1125        desc_key: "cmd.jump_to_next_error_desc",
1126        action: || Action::JumpToNextError,
1127        contexts: &[Normal],
1128        custom_contexts: &[],
1129    },
1130    CommandDef {
1131        name_key: "cmd.jump_to_previous_error",
1132        desc_key: "cmd.jump_to_previous_error_desc",
1133        action: || Action::JumpToPreviousError,
1134        contexts: &[Normal],
1135        custom_contexts: &[],
1136    },
1137    // LSP
1138    CommandDef {
1139        name_key: "cmd.rename_symbol",
1140        desc_key: "cmd.rename_symbol_desc",
1141        action: || Action::LspRename,
1142        contexts: &[Normal],
1143        custom_contexts: &[],
1144    },
1145    // Bookmarks and Macros
1146    CommandDef {
1147        name_key: "cmd.list_bookmarks",
1148        desc_key: "cmd.list_bookmarks_desc",
1149        action: || Action::ListBookmarks,
1150        contexts: &[Normal],
1151        custom_contexts: &[],
1152    },
1153    CommandDef {
1154        name_key: "cmd.list_macros",
1155        desc_key: "cmd.list_macros_desc",
1156        action: || Action::ListMacros,
1157        contexts: &[Normal],
1158        custom_contexts: &[],
1159    },
1160    CommandDef {
1161        name_key: "cmd.record_macro",
1162        desc_key: "cmd.record_macro_desc",
1163        action: || Action::PromptRecordMacro,
1164        contexts: &[Normal],
1165        custom_contexts: &[],
1166    },
1167    CommandDef {
1168        name_key: "cmd.stop_recording_macro",
1169        desc_key: "cmd.stop_recording_macro_desc",
1170        action: || Action::StopMacroRecording,
1171        contexts: &[Normal],
1172        custom_contexts: &[],
1173    },
1174    CommandDef {
1175        name_key: "cmd.play_macro",
1176        desc_key: "cmd.play_macro_desc",
1177        action: || Action::PromptPlayMacro,
1178        contexts: &[Normal],
1179        custom_contexts: &[],
1180    },
1181    CommandDef {
1182        name_key: "cmd.play_last_macro",
1183        desc_key: "cmd.play_last_macro_desc",
1184        action: || Action::PlayLastMacro,
1185        contexts: &[Normal],
1186        custom_contexts: &[],
1187    },
1188    CommandDef {
1189        name_key: "cmd.set_bookmark",
1190        desc_key: "cmd.set_bookmark_desc",
1191        action: || Action::PromptSetBookmark,
1192        contexts: &[Normal],
1193        custom_contexts: &[],
1194    },
1195    CommandDef {
1196        name_key: "cmd.jump_to_bookmark",
1197        desc_key: "cmd.jump_to_bookmark_desc",
1198        action: || Action::PromptJumpToBookmark,
1199        contexts: &[Normal],
1200        custom_contexts: &[],
1201    },
1202    // Help
1203    CommandDef {
1204        name_key: "cmd.show_manual",
1205        desc_key: "cmd.show_manual_desc",
1206        action: || Action::ShowHelp,
1207        contexts: &[],
1208        custom_contexts: &[],
1209    },
1210    CommandDef {
1211        name_key: "cmd.show_keyboard_shortcuts",
1212        desc_key: "cmd.show_keyboard_shortcuts_desc",
1213        action: || Action::ShowKeyboardShortcuts,
1214        contexts: &[],
1215        custom_contexts: &[],
1216    },
1217    CommandDef {
1218        name_key: "cmd.show_warnings",
1219        desc_key: "cmd.show_warnings_desc",
1220        action: || Action::ShowWarnings,
1221        contexts: &[],
1222        custom_contexts: &[],
1223    },
1224    CommandDef {
1225        name_key: "cmd.show_lsp_status",
1226        desc_key: "cmd.show_lsp_status_desc",
1227        action: || Action::ShowLspStatus,
1228        contexts: &[],
1229        custom_contexts: &[],
1230    },
1231    CommandDef {
1232        name_key: "cmd.show_remote_indicator_menu",
1233        desc_key: "cmd.show_remote_indicator_menu_desc",
1234        action: || Action::ShowRemoteIndicatorMenu,
1235        contexts: &[],
1236        custom_contexts: &[],
1237    },
1238    CommandDef {
1239        name_key: "cmd.clear_warnings",
1240        desc_key: "cmd.clear_warnings_desc",
1241        action: || Action::ClearWarnings,
1242        contexts: &[],
1243        custom_contexts: &[],
1244    },
1245    // Config
1246    CommandDef {
1247        name_key: "cmd.dump_config",
1248        desc_key: "cmd.dump_config_desc",
1249        action: || Action::DumpConfig,
1250        contexts: &[],
1251        custom_contexts: &[],
1252    },
1253    CommandDef {
1254        name_key: "cmd.redraw_screen",
1255        desc_key: "cmd.redraw_screen_desc",
1256        action: || Action::RedrawScreen,
1257        contexts: &[],
1258        custom_contexts: &[],
1259    },
1260    CommandDef {
1261        name_key: "cmd.toggle_inlay_hints",
1262        desc_key: "cmd.toggle_inlay_hints_desc",
1263        action: || Action::ToggleInlayHints,
1264        contexts: &[Normal],
1265        custom_contexts: &[],
1266    },
1267    // Theme selection
1268    CommandDef {
1269        name_key: "cmd.select_theme",
1270        desc_key: "cmd.select_theme_desc",
1271        action: || Action::SelectTheme,
1272        contexts: &[],
1273        custom_contexts: &[],
1274    },
1275    // Theme inspection
1276    CommandDef {
1277        name_key: "cmd.inspect_theme_at_cursor",
1278        desc_key: "cmd.inspect_theme_at_cursor_desc",
1279        action: || Action::InspectThemeAtCursor,
1280        contexts: &[Normal],
1281        custom_contexts: &[],
1282    },
1283    // Keybinding map selection
1284    CommandDef {
1285        name_key: "cmd.select_keybinding_map",
1286        desc_key: "cmd.select_keybinding_map_desc",
1287        action: || Action::SelectKeybindingMap,
1288        contexts: &[],
1289        custom_contexts: &[],
1290    },
1291    // Cursor style selection
1292    CommandDef {
1293        name_key: "cmd.select_cursor_style",
1294        desc_key: "cmd.select_cursor_style_desc",
1295        action: || Action::SelectCursorStyle,
1296        contexts: &[],
1297        custom_contexts: &[],
1298    },
1299    // Locale selection
1300    CommandDef {
1301        name_key: "cmd.select_locale",
1302        desc_key: "cmd.select_locale_desc",
1303        action: || Action::SelectLocale,
1304        contexts: &[],
1305        custom_contexts: &[],
1306    },
1307    // Settings
1308    CommandDef {
1309        name_key: "cmd.open_settings",
1310        desc_key: "cmd.open_settings_desc",
1311        action: || Action::OpenSettings,
1312        contexts: &[],
1313        custom_contexts: &[],
1314    },
1315    // Keybinding editor
1316    CommandDef {
1317        name_key: "cmd.open_keybinding_editor",
1318        desc_key: "cmd.open_keybinding_editor_desc",
1319        action: || Action::OpenKeybindingEditor,
1320        contexts: &[],
1321        custom_contexts: &[],
1322    },
1323    // Input calibration
1324    CommandDef {
1325        name_key: "cmd.calibrate_input",
1326        desc_key: "cmd.calibrate_input_desc",
1327        action: || Action::CalibrateInput,
1328        contexts: &[],
1329        custom_contexts: &[],
1330    },
1331    // Terminal commands
1332    CommandDef {
1333        name_key: "cmd.open_terminal",
1334        desc_key: "cmd.open_terminal_desc",
1335        action: || Action::OpenTerminal,
1336        contexts: &[],
1337        custom_contexts: &[],
1338    },
1339    CommandDef {
1340        name_key: "cmd.focus_terminal",
1341        desc_key: "cmd.focus_terminal_desc",
1342        action: || Action::FocusTerminal,
1343        contexts: &[Normal],
1344        custom_contexts: &[],
1345    },
1346    CommandDef {
1347        name_key: "cmd.send_selection_to_terminal",
1348        desc_key: "cmd.send_selection_to_terminal_desc",
1349        action: || Action::SendSelectionToTerminal,
1350        contexts: &[Normal],
1351        custom_contexts: &[],
1352    },
1353    CommandDef {
1354        name_key: "cmd.exit_terminal_mode",
1355        desc_key: "cmd.exit_terminal_mode_desc",
1356        action: || Action::TerminalEscape,
1357        contexts: &[Terminal],
1358        custom_contexts: &[],
1359    },
1360    CommandDef {
1361        name_key: "cmd.toggle_keyboard_capture",
1362        desc_key: "cmd.toggle_keyboard_capture_desc",
1363        action: || Action::ToggleKeyboardCapture,
1364        contexts: &[Terminal],
1365        custom_contexts: &[],
1366    },
1367    // Shell command operations
1368    CommandDef {
1369        name_key: "cmd.shell_command",
1370        desc_key: "cmd.shell_command_desc",
1371        action: || Action::ShellCommand,
1372        contexts: &[Normal],
1373        custom_contexts: &[],
1374    },
1375    CommandDef {
1376        name_key: "cmd.shell_command_replace",
1377        desc_key: "cmd.shell_command_replace_desc",
1378        action: || Action::ShellCommandReplace,
1379        contexts: &[Normal],
1380        custom_contexts: &[],
1381    },
1382    // Debugging
1383    CommandDef {
1384        name_key: "cmd.event_debug",
1385        desc_key: "cmd.event_debug_desc",
1386        action: || Action::EventDebug,
1387        contexts: &[],
1388        custom_contexts: &[],
1389    },
1390    // Process control (Unix job-control suspend)
1391    CommandDef {
1392        name_key: "cmd.suspend_process",
1393        desc_key: "cmd.suspend_process_desc",
1394        action: || Action::SuspendProcess,
1395        contexts: &[Normal, FileExplorer, Terminal],
1396        custom_contexts: &[],
1397    },
1398    // Plugin development
1399    CommandDef {
1400        name_key: "cmd.load_plugin_from_buffer",
1401        desc_key: "cmd.load_plugin_from_buffer_desc",
1402        action: || Action::LoadPluginFromBuffer,
1403        contexts: &[Normal],
1404        custom_contexts: &[],
1405    },
1406    // User init.ts
1407    CommandDef {
1408        name_key: "cmd.init_reload",
1409        desc_key: "cmd.init_reload_desc",
1410        action: || Action::InitReload,
1411        contexts: &[Normal],
1412        custom_contexts: &[],
1413    },
1414    CommandDef {
1415        name_key: "cmd.init_edit",
1416        desc_key: "cmd.init_edit_desc",
1417        action: || Action::InitEdit,
1418        contexts: &[Normal],
1419        custom_contexts: &[],
1420    },
1421    CommandDef {
1422        name_key: "cmd.init_check",
1423        desc_key: "cmd.init_check_desc",
1424        action: || Action::InitCheck,
1425        contexts: &[Normal],
1426        custom_contexts: &[],
1427    },
1428    // Live Grep (issue #1796) — `cmd.live_grep` itself is registered
1429    // by the live_grep plugin (palette title is plugin-controlled);
1430    // these are the editor-side actions that should also be palette-
1431    // discoverable so the user can find them by name.
1432    CommandDef {
1433        name_key: "cmd.resume_live_grep",
1434        desc_key: "cmd.resume_live_grep_desc",
1435        action: || Action::ResumeLiveGrep,
1436        contexts: &[Normal],
1437        custom_contexts: &[],
1438    },
1439    CommandDef {
1440        name_key: "cmd.toggle_utility_dock",
1441        desc_key: "cmd.toggle_utility_dock_desc",
1442        action: || Action::ToggleUtilityDock,
1443        contexts: &[Normal],
1444        custom_contexts: &[],
1445    },
1446    CommandDef {
1447        name_key: "cmd.open_terminal_in_dock",
1448        desc_key: "cmd.open_terminal_in_dock_desc",
1449        action: || Action::OpenTerminalInDock,
1450        contexts: &[Normal],
1451        custom_contexts: &[],
1452    },
1453    // Workspace trust — a single command that opens the trust dialog; the
1454    // dialog itself is where the level is chosen.
1455    CommandDef {
1456        name_key: "cmd.workspace_trust",
1457        desc_key: "cmd.workspace_trust_desc",
1458        action: || Action::WorkspaceTrustPrompt,
1459        contexts: &[],
1460        custom_contexts: &[],
1461    },
1462];
1463
1464/// Get all available commands for the command palette
1465pub fn get_all_commands() -> Vec<Command> {
1466    COMMAND_DEFS
1467        .iter()
1468        .map(|def| Command {
1469            name: t!(def.name_key).to_string(),
1470            description: t!(def.desc_key).to_string(),
1471            action: (def.action)(),
1472            contexts: def.contexts.to_vec(),
1473            custom_contexts: def.custom_contexts.iter().map(|s| s.to_string()).collect(),
1474            source: CommandSource::Builtin,
1475            // Built-in commands use the legacy `is_terminal_ui_action`
1476            // path; the plugin-driven `terminal_bypass` flag isn't
1477            // wired into them.
1478            terminal_bypass: false,
1479        })
1480        .collect()
1481}
1482
1483/// Filter commands by fuzzy matching the query, with context awareness
1484pub fn filter_commands(
1485    query: &str,
1486    current_context: KeyContext,
1487    keybinding_resolver: &crate::input::keybindings::KeybindingResolver,
1488) -> Vec<Suggestion> {
1489    let query_lower = query.to_lowercase();
1490    let commands = get_all_commands();
1491
1492    // Helper function to check if command is available in current context
1493    let is_available = |cmd: &Command| -> bool {
1494        // Empty contexts means available in all contexts
1495        cmd.contexts.is_empty() || cmd.contexts.contains(&current_context)
1496    };
1497
1498    // Helper function for fuzzy matching
1499    let matches_query = |cmd: &Command| -> bool {
1500        if query.is_empty() {
1501            return true;
1502        }
1503
1504        let name_lower = cmd.name.to_lowercase();
1505        let mut query_chars = query_lower.chars();
1506        let mut current_char = query_chars.next();
1507
1508        for name_char in name_lower.chars() {
1509            if let Some(qc) = current_char {
1510                if qc == name_char {
1511                    current_char = query_chars.next();
1512                }
1513            } else {
1514                break;
1515            }
1516        }
1517
1518        current_char.is_none() // All query characters matched
1519    };
1520
1521    // Filter and convert to suggestions
1522    let current_context_ref = &current_context;
1523    let mut suggestions: Vec<Suggestion> = commands
1524        .into_iter()
1525        .filter(|cmd| matches_query(cmd))
1526        .map(|cmd| {
1527            let available = is_available(&cmd);
1528            let keybinding = keybinding_resolver
1529                .get_keybinding_for_action(&cmd.action, current_context_ref.clone());
1530            Suggestion::new(cmd.name.clone())
1531                .with_description(cmd.description)
1532                .set_disabled(!available)
1533                .with_keybinding(keybinding)
1534        })
1535        .collect();
1536
1537    // Sort: available commands first, then disabled ones
1538    suggestions.sort_by_key(|s| s.disabled);
1539
1540    suggestions
1541}