Skip to content

Commit

Permalink
Check modifier key equality correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBestTvarynka authored Oct 26, 2024
1 parent 3f887a2 commit 669416d
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions leptos_hotkeys/src/hotkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,32 +98,44 @@ pub(crate) fn is_hotkey_match(
) -> bool {
let mut modifiers_match = true;

let is_ctrl_pressed = pressed_keyset.contains_key("controlleft")
|| pressed_keyset.contains_key("controlright")
|| pressed_keyset.contains_key("control");
if hotkey.modifiers.ctrl {
modifiers_match &= pressed_keyset.contains_key("controlleft")
|| pressed_keyset.contains_key("controlright")
|| pressed_keyset.contains_key("control");
modifiers_match &= is_ctrl_pressed;
} else {
modifiers_match &= !is_ctrl_pressed;
}

let is_shift_pressed = pressed_keyset.contains_key("shiftleft")
|| pressed_keyset.contains_key("shiftright")
|| pressed_keyset.contains_key("shift");
if hotkey.modifiers.shift {
modifiers_match &= pressed_keyset.contains_key("shiftleft")
|| pressed_keyset.contains_key("shiftright")
|| pressed_keyset.contains_key("shift");
modifiers_match &= is_shift_pressed;
} else {
modifiers_match &= !is_shift_pressed;
}

let is_meta_pressed = pressed_keyset.contains_key("metaleft")
|| pressed_keyset.contains_key("metaright")
|| pressed_keyset.contains_key("meta")
|| pressed_keyset.contains_key("command")
|| pressed_keyset.contains_key("cmd")
|| pressed_keyset.contains_key("super")
|| pressed_keyset.contains_key("win");
if hotkey.modifiers.meta {
modifiers_match &= pressed_keyset.contains_key("metaleft")
|| pressed_keyset.contains_key("metaright")
|| pressed_keyset.contains_key("meta")
|| pressed_keyset.contains_key("command")
|| pressed_keyset.contains_key("cmd")
|| pressed_keyset.contains_key("super")
|| pressed_keyset.contains_key("win");
modifiers_match &= is_meta_pressed;
} else {
modifiers_match &= !is_meta_pressed;
}

let is_alt_pressed = pressed_keyset.contains_key("altleft")
|| pressed_keyset.contains_key("altright")
|| pressed_keyset.contains_key("alt");
if hotkey.modifiers.alt {
modifiers_match &= pressed_keyset.contains_key("altleft")
|| pressed_keyset.contains_key("altright")
|| pressed_keyset.contains_key("alt");
modifiers_match &= is_alt_pressed;
} else {
modifiers_match &= !is_alt_pressed;
}

if modifiers_match {
Expand Down

0 comments on commit 669416d

Please sign in to comment.