diff --git a/src/main.rs b/src/main.rs index e26379c..fb38594 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1427,6 +1427,7 @@ enum Message { OpenShortcutCapture(ShortcutAction), CancelShortcut, ClearShortcut(ShortcutAction), + DefaultShortcut(ShortcutAction), ApplyShortcut, CaptureKey { key: keyboard::Key, @@ -1952,6 +1953,12 @@ fn update(state: &mut Moorly, message: Message) -> Task { state.shortcuts.set(action, None); state.shortcut_capture = None; } + Message::DefaultShortcut(action) => { + state + .shortcuts + .set(action, Shortcuts::default().get(action).cloned()); + state.shortcut_capture = None; + } Message::ApplyShortcut => apply_shortcut(state), Message::CaptureKey { key, modifiers } => match key { keyboard::Key::Named(keyboard::key::Named::Escape) => { @@ -2474,6 +2481,9 @@ fn shortcut_row( row![ container(text(action.label())).width(120), field, + button("Default") + .on_press(Message::DefaultShortcut(action)) + .style(theme::outlined_option), button("None") .on_press(Message::ClearShortcut(action)) .style(theme::outlined_option), @@ -4311,6 +4321,26 @@ mod tests { assert!(state.shortcuts.quit.is_some()); } + #[test] + fn restoring_a_shortcut_default_rebinds_it() { + let mut state = state(); + let _ = update( + &mut state, + Message::ClearShortcut(super::ShortcutAction::Settings), + ); + assert!(state.shortcuts.settings.is_none()); + + let _ = update( + &mut state, + Message::DefaultShortcut(super::ShortcutAction::Settings), + ); + + assert_eq!( + state.shortcuts.settings.as_ref().map(ToString::to_string), + Some("Ctrl+,".to_owned()) + ); + } + #[test] fn quit_has_a_default_shortcut() { let state = state();