Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Keybinds): Fix keybinds order when recording #1918

Merged
merged 3 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions common/src/state/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions ui/src/components/settings/sub_pages/keybinds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 |_| {
Expand Down
Loading