From cb635ab2fe87db069eec47fde115228675ddd303 Mon Sep 17 00:00:00 2001 From: lgmarchi <lucasgmarchi@gmail.com> Date: Mon, 11 Mar 2024 10:23:57 -0300 Subject: [PATCH] fix(Keybinds): Fix keybinds order when recording --- common/src/state/settings.rs | 19 +++++++++++++++++++ .../components/settings/sub_pages/keybinds.rs | 5 +++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/common/src/state/settings.rs b/common/src/state/settings.rs index 2fae911d18a..390275b3af8 100644 --- a/common/src/state/settings.rs +++ b/common/src/state/settings.rs @@ -60,6 +60,25 @@ impl Shortcut { .unwrap_or(false) } + pub fn reorder_keybind_string(mut keybinds: Vec<String>) -> Vec<String> { + keybinds.sort_by(|a, b| match (a.as_str(), b.as_str()) { + ("Command", "Shift") + | ("Command", "Alt") + | ("Ctrl", "Shift") + | ("Ctrl", "Alt") + | ("Ctrl", "Command") => std::cmp::Ordering::Less, + ("Shift", "Alt") => std::cmp::Ordering::Less, + ("Shift", "Command") => std::cmp::Ordering::Greater, + ("Shift", "Ctrl") => std::cmp::Ordering::Greater, + ("Alt", _) => std::cmp::Ordering::Less, + ("Ctrl", _) => std::cmp::Ordering::Less, + ("Command", _) => std::cmp::Ordering::Less, + ("Shift", _) => std::cmp::Ordering::Less, + _ => std::cmp::Ordering::Equal, + }); + keybinds + } + pub fn get_keys_and_modifiers_as_string(&self) -> Vec<String> { let key_code_strs: Vec<String> = self .keys diff --git a/ui/src/components/settings/sub_pages/keybinds.rs b/ui/src/components/settings/sub_pages/keybinds.rs index 306932c4b73..77d4f844c49 100644 --- a/ui/src/components/settings/sub_pages/keybinds.rs +++ b/ui/src/components/settings/sub_pages/keybinds.rs @@ -189,7 +189,6 @@ pub fn KeybindSection(cx: Scope<KeybindSectionProps>) -> Element { is_recording.set(true); }, onkeydown: move |evt| { - // println!("evt: {:?}", evt); if evt.data.code() == Code::Escape { is_recording.set(false); @@ -210,7 +209,9 @@ pub fn KeybindSection(cx: Scope<KeybindSectionProps>) -> Element { binding.extend(modifier_string_vec); } - recorded_bindings.set(binding); + let binding2 = Shortcut::reorder_keybind_string(binding); + + recorded_bindings.set(binding2); evt.stop_propagation(); }, onkeyup: move |_| {