Added shortcut into command palette command listings if there is a set shortcut for a specific command
Moorly CI / windows-build (push) Successful in 2m52s
Moorly CI / linux-build (push) Successful in 3m32s

This commit is contained in:
Squid committed 2026-11-08 12:11:21 +01:00
1 parent 2106c88868
commit df19d1dd5d
1 file changed
+123 -12
+123 -12
View File
@@ -1279,6 +1279,20 @@ impl Command {
}
}
/// The shortcut configured for this command, if it has one.
fn shortcut(&self, state: &Moorly) -> Option<String> {
let action = match self {
Self::Settings => ShortcutAction::Settings,
Self::Exit => ShortcutAction::Quit,
Self::QuickTerminal => ShortcutAction::QuickTerminal,
Self::QuickSsh => ShortcutAction::QuickSsh,
Self::Close => return Some("Ctrl+Shift+W".to_owned()),
_ => return None,
};
state.shortcuts.get(action).map(ToString::to_string)
}
/// Left/Right only exist while there is a tab to switch to.
fn available(&self, state: &Moorly, window: window::Id) -> bool {
match self {
@@ -1476,6 +1490,8 @@ struct Moorly {
hide_tab_close_draft: bool,
show_new_session_button: bool,
show_new_session_button_draft: bool,
show_command_palette_description: bool,
show_command_palette_description_draft: bool,
command_palette_enabled: bool,
command_palette_enabled_draft: bool,
advanced_open: bool,
@@ -1880,6 +1896,8 @@ struct AppearanceConfig {
hide_tab_close: bool,
#[serde(default = "default_true")]
show_new_session_button: bool,
#[serde(default = "default_true")]
show_command_palette_description: bool,
#[serde(default)]
toast: ToastFile,
}
@@ -1892,6 +1910,7 @@ impl Default for AppearanceConfig {
custom_theme_name: None,
hide_tab_close: true,
show_new_session_button: true,
show_command_palette_description: true,
toast: ToastFile::default(),
}
}
@@ -3561,6 +3580,7 @@ fn apply_settings(state: &mut Moorly) {
state.fade_settings = state.fade_settings_draft;
state.hide_tab_close = state.hide_tab_close_draft;
state.show_new_session_button = state.show_new_session_button_draft;
state.show_command_palette_description = state.show_command_palette_description_draft;
state.command_palette_enabled = state.command_palette_enabled_draft;
state.saved_theme = state.theme;
@@ -3596,6 +3616,7 @@ fn undo_settings(state: &mut Moorly) {
state.fade_settings_draft = state.fade_settings;
state.hide_tab_close_draft = state.hide_tab_close;
state.show_new_session_button_draft = state.show_new_session_button;
state.show_command_palette_description_draft = state.show_command_palette_description;
state.command_palette_enabled_draft = state.command_palette_enabled;
state.shortcuts = state.saved_shortcuts.clone();
state.shortcut_capture = None;
@@ -3657,6 +3678,7 @@ fn config_file(state: &Moorly) -> ConfigFile {
},
hide_tab_close: state.hide_tab_close,
show_new_session_button: state.show_new_session_button,
show_command_palette_description: state.show_command_palette_description,
toast: ToastFile::from_colors(state.builtin_custom_toasts, &state.builtin_toast_colors),
},
shortcuts: ShortcutConfig {
@@ -3709,6 +3731,7 @@ impl Default for Moorly {
let fade_settings = config.general.fade_settings;
let hide_tab_close = config.appearance.hide_tab_close;
let show_new_session_button = config.appearance.show_new_session_button;
let show_command_palette_description = config.appearance.show_command_palette_description;
let command_palette_enabled = config.command_palette.enabled;
let shortcuts = Shortcuts {
settings: Shortcut::parse(&config.shortcuts.settings),
@@ -3751,6 +3774,8 @@ impl Default for Moorly {
hide_tab_close_draft: hide_tab_close,
show_new_session_button,
show_new_session_button_draft: show_new_session_button,
show_command_palette_description,
show_command_palette_description_draft: show_command_palette_description,
command_palette_enabled,
command_palette_enabled_draft: command_palette_enabled,
advanced_open: false,
@@ -3828,6 +3853,7 @@ enum Message {
SetFadeSettings(bool),
SetHideTabClose(bool),
SetShowNewSessionButton(bool),
SetShowCommandPaletteDescription(bool),
SetCommandPaletteEnabled(bool),
ToggleAdvanced,
SetCustomToasts(bool),
@@ -4450,6 +4476,9 @@ fn update(state: &mut Moorly, message: Message) -> Task<Message> {
Message::SetFadeSettings(value) => state.fade_settings_draft = value,
Message::SetHideTabClose(value) => state.hide_tab_close_draft = value,
Message::SetShowNewSessionButton(value) => state.show_new_session_button_draft = value,
Message::SetShowCommandPaletteDescription(value) => {
state.show_command_palette_description_draft = value;
}
Message::SetCommandPaletteEnabled(value) => {
state.command_palette_enabled_draft = value;
}
@@ -7770,6 +7799,14 @@ fn appearance_panel(state: &Moorly) -> Element<'_, Message> {
toggler(state.hide_tab_close_draft).on_toggle(Message::SetHideTabClose),
]
.align_y(Alignment::Center),
text("Command Palette").size(SETTINGS_H2_SIZE),
row![
text("Show command palette description").size(SETTINGS_H3_SIZE),
space::horizontal(),
toggler(state.show_command_palette_description_draft)
.on_toggle(Message::SetShowCommandPaletteDescription),
]
.align_y(Alignment::Center),
]
.spacing(12)
.into()
@@ -7933,6 +7970,7 @@ fn settings_page(state: &Moorly, window: window::Id) -> Element<'_, Message> {
|| state.fade_settings_draft != state.fade_settings
|| state.hide_tab_close_draft != state.hide_tab_close
|| state.show_new_session_button_draft != state.show_new_session_button
|| state.show_command_palette_description_draft != state.show_command_palette_description
|| state.command_palette_enabled_draft != state.command_palette_enabled
|| state.theme_choice != state.saved_theme_choice
|| state.shortcuts != state.saved_shortcuts;
@@ -8422,30 +8460,29 @@ fn main_view(state: &Moorly, window: window::Id) -> Element<'_, Message> {
root.into()
}
/// One command row: name over description, with the Enter hint on the
/// selected row.
/// One command row: name over description and shortcut, with the Enter hint
/// on the selected row. Descriptions and shortcuts follow the appearance
/// setting.
fn command_palette_item(
state: &Moorly,
window: window::Id,
command: Command,
selected: bool,
) -> Element<'static, Message> {
let mut title = row![].spacing(8).align_y(Alignment::Center);
let show_description = state.show_command_palette_description;
let mut title = row![]
.spacing(8)
.align_y(Alignment::Center)
.width(Length::Fill);
if let Some((kind, color)) = command.profile_glyph(state) {
title = title.push(profile_glyph(kind, color));
}
title = title.push(text(command.label(state)).size(16));
let details = column![title, text(command.description(state)).size(12)].spacing(2);
let mut content = row![details.width(Length::Fill)]
.align_y(Alignment::Center)
.height(Length::Fill);
if selected {
content = content.push(
title = title.push(space::horizontal()).push(
container(text("Enter").size(11))
.height(Length::Fill)
.align_y(Alignment::Center)
.padding([0, 8])
.style(|theme: &iced::Theme| {
@@ -8463,10 +8500,30 @@ fn command_palette_item(
);
}
let mut details = column![title].spacing(2);
if show_description {
let mut info = row![]
.spacing(8)
.align_y(Alignment::Center)
.width(Length::Fill);
info = info.push(text(command.description(state)).size(12));
if let Some(shortcut) = command.shortcut(state) {
info = info.push(space::horizontal()).push(text(shortcut).size(11));
}
details = details.push(info);
}
let content = row![details.width(Length::Fill)]
.align_y(Alignment::Center)
.height(Length::Fill);
button(content)
.on_press(Message::RunCommand(window, command))
.width(Length::Fill)
.height(52)
.height(if show_description { 52 } else { 34 })
.padding([4, 10])
.style(move |theme, status| theme::selectable_row(theme, status, selected))
.into()
@@ -8602,6 +8659,8 @@ mod tests {
hide_tab_close_draft: true,
show_new_session_button: true,
show_new_session_button_draft: true,
show_command_palette_description: true,
show_command_palette_description_draft: true,
command_palette_enabled: true,
command_palette_enabled_draft: true,
advanced_open: false,
@@ -8766,6 +8825,29 @@ mod tests {
assert!(super::tab_strip_width(1024.0, false) > super::tab_strip_width(1024.0, true));
}
#[test]
fn hiding_command_palette_descriptions_waits_for_save_or_undo() {
let mut state = state();
let _ = update(&mut state, Message::SetShowCommandPaletteDescription(false));
assert!(state.show_command_palette_description);
assert!(!state.show_command_palette_description_draft);
let _ = update(&mut state, Message::UndoChanges);
assert_eq!(
state.show_command_palette_description_draft,
state.show_command_palette_description
);
let _ = update(&mut state, Message::SetShowCommandPaletteDescription(false));
super::apply_settings(&mut state);
assert!(!state.show_command_palette_description);
assert_eq!(
state.show_command_palette_description_draft,
state.show_command_palette_description
);
}
#[test]
fn disabling_the_command_palette_waits_for_save_or_undo() {
let mut state = state();
@@ -8819,6 +8901,7 @@ mod tests {
state.show_start_tab = false;
state.hide_tab_close = false;
state.show_new_session_button = false;
state.show_command_palette_description = false;
state.command_palette_enabled = false;
state.saved_theme = theme::Preference::Dark;
state.saved_theme_choice = super::ThemeChoice::BuiltIn(theme::Preference::Dark);
@@ -8833,6 +8916,7 @@ mod tests {
assert!(text.contains("[startup]\nshow_start_tab = false"));
assert!(text.contains("[appearance]\ntheme = \"dark\""));
assert!(text.contains("show_new_session_button = false"));
assert!(text.contains("show_command_palette_description = false"));
assert!(text.contains("[appearance.toast]"));
assert!(text.contains("[shortcuts]"));
assert!(text.contains("[command_palette]\nenabled = false"));
@@ -9409,6 +9493,33 @@ mod tests {
assert!(!window_state(&state).quick_menu_open);
}
#[test]
fn commands_report_their_configured_shortcuts() {
let state = state();
assert_eq!(
super::Command::Settings.shortcut(&state),
Some("Ctrl+,".to_owned())
);
assert_eq!(
super::Command::Exit.shortcut(&state),
Some("Ctrl+Shift+Q".to_owned())
);
assert_eq!(
super::Command::QuickTerminal.shortcut(&state),
Some("Ctrl+Shift+T".to_owned())
);
assert_eq!(
super::Command::QuickSsh.shortcut(&state),
Some("Ctrl+Shift+S".to_owned())
);
assert_eq!(
super::Command::Close.shortcut(&state),
Some("Ctrl+Shift+W".to_owned())
);
assert_eq!(super::Command::Left.shortcut(&state), None);
}
#[test]
fn quick_commands_are_in_the_palette_and_do_nothing_yet() {
let mut state = state();