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

Unclear how to differentiate between hotkey with modifiers and without #141

Open
wrl opened this issue Oct 14, 2024 · 1 comment
Open

Unclear how to differentiate between hotkey with modifiers and without #141

wrl opened this issue Oct 14, 2024 · 1 comment
Labels
feature New feature or request improvement

Comments

@wrl
Copy link

wrl commented Oct 14, 2024

I've got two hotkey handlers:

    use_hotkeys!(("tab") => move |_| {
        log!("just the tab");
    });

    use_hotkeys!(("shift+tab") => move |_| {
        log!("the shift+tab");
    });

Whenever I press Shift+Tab, the tab handler fires as well. Is there a way to prevent this?

@friendlymatthew
Copy link
Member

friendlymatthew commented Oct 16, 2024

Thank you for opening your first issue! Welcome 🎉

Tl;dr: There is no current way to prevent this. However a solution does exist, I just don't have the time or energy to implement it currently. If you're able to contribute, that would be more than awesome 🤠 😸.

Here's some more detail about this issue:

The current matching logic is greedy.

Meaning that if a hotkey is a direct subset of another hotkey, the subset hotkey logic will always fire.

A hotkey binding is represented as a HashSet of keys. Using your example, let hotkey A be set("tab") and hotkey B be set("shift", "tab"). Since A is a subset of B, when we match, A will always be fired over B.

The solution

#2 is a feature request directly for this use case. The trick is to introduce some window of time after the first key press. We wait for all the other keys to be pressed and once that window is up, we can evaluate it.

Let me know if you want to work on this! This would be a major upgrade to what we currently have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request improvement
Projects
None yet
Development

No branches or pull requests

2 participants