You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: (Macos) pressing cmd+c or any shortcut that has cmd in it will break any registered shortcuts unless the window goes blur #576
Past that, the test suite of this library should encompass any edge-cases and they currently pass. If there's an issue with unsetting shortcuts, you're welcome to submit a PR with a failing test case and fix.
I don't mean to brag or be rude but not wrapping it in useCallback and not putting it in the dependency array is only a bad practise but it definitely is not the cause of the issue. I am well aware that not putting the callback in the dep array can potentially cause issues (stale functional reference) but that's precisely why I am passing a callback to setShow instead of using show state value.
To demonstrate this when I am pressing & holding the cmd key followed by pressing and holding the k key. So now I have both cmd & k on hold. The keydown fired for both. But if I now release k there won't be a keyup event for k since cmd is pressed. So to get the keyup event for k I need to release the cmd key before releasing k.
Looking at the code it seems that you are not clearing the keyDowns array since there is no keyup for k when cmd is being held. A simple solution would be to reset the keyDowns ref array after a slight delay irrespective of the keyup event was found or not.
If there's an issue with unsetting shortcuts, you're welcome to submit a PR with a failing test case and fix.
This can't be replicated through a testing library because you are firing the events yourself. While irl behaviour is out of the ordinary.
It's certainly not bragging to be wrong about how to use hooks properly. Regardless, as stated in the original reply, you're welcome to submit a PR with a new test case and fix to address the problem.
Activity
tlackemann commentedon Oct 7, 2024
Thanks for filing an issue.
Taking a quick look at the sample app attached, there's an issue that could possibly be related.
handleShortcutshould be auseCallbackand passed as a dependency to theuseEffectPast that, the test suite of this library should encompass any edge-cases and they currently pass. If there's an issue with unsetting shortcuts, you're welcome to submit a PR with a failing test case and fix.
whoami-amrit commentedon Oct 8, 2024
I don't mean to
brag orbe rude but not wrapping it in useCallback and not putting it in the dependency array is only a bad practise but it definitely is not the cause of the issue. I am well aware that not putting the callback in the dep array can potentially cause issues (stale functional reference) but that's precisely why I am passing a callback tosetShowinstead of usingshowstate value.The problem might be related to this https://stackoverflow.com/questions/27380018/when-cmd-key-is-kept-pressed-keyup-is-not-triggered-for-any-other-key
To demonstrate this when I am pressing & holding the
cmdkey followed by pressing and holding thekkey. So now I have bothcmd&kon hold. The keydown fired for both. But if I now releasekthere won't be a keyup event for k sincecmdis pressed. So to get the keyup event forkI need to release thecmdkey before releasingk.Looking at the code it seems that you are not clearing the keyDowns array since there is no keyup for
kwhencmdis being held. A simple solution would be to reset the keyDowns ref array after a slight delay irrespective of the keyup event was found or not.This can't be replicated through a testing library because you are firing the events yourself. While irl behaviour is out of the ordinary.
tlackemann commentedon Oct 10, 2024
It's certainly not bragging to be wrong about how to use hooks properly. Regardless, as stated in the original reply, you're welcome to submit a PR with a new test case and fix to address the problem.
whoami-amrit commentedon Oct 14, 2024
Hi ! @tlackemann . I opened a little PR for this issue. Thanks.
algonzale commentedon Oct 17, 2024
Bump. I am experiencing this as well.
tapegram commentedon Nov 20, 2024
Also experiencing this!