Improve issue where keyup is not fired when command key is pressed / 修复 command 键按下时 keyup 不触发的问题 #502
+7
−8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
中文见下方
Currently, if one were to register two hotkeys with command key like "Command + Shift + ArrowLeft" and "Command + Shift + ArrowRight", they will not be reliably triggered. To reproduce:
The reason of this issue is that when command key is pressed,
keyup
for a non-modifier key will not trigger. This is a known browser limitation. As a result, hotkeys never knew about the left arrow being let go. In its internal state, when the right arrow is pressed, the_downKeys
include both arrow left and arrow right. This is incorrect.This PR brings a solution where, if command key is pressed, any non-modifier key that is not the event key will be removed from
_downKeys
. Becausekeyup
is never fired for them, we need to manually release them when command is pressed.当前注册多个带有command的hotkeys(比如“Command + Shift + ArrowLeft”和“Command + Shift + ArrowRight”)的情况下,触发不稳定。重现步骤如下:
出现此问题的原因是,当 command 键被按下时,非修饰键的
keyup
事件不会触发。这是已知的浏览器限制。结果就是快捷键内部状态无法得知左箭头键已被释放。在上面提到的例子中,当按下右箭头键时,内部状态中_downKeys
包含了左箭头键和右箭头键。这就不对了。此 PR 提供的解决方案是:当 command 键被按下时,任何不是当前事件触发的非修饰键都会从
_downKeys
中移除。由于它们的keyup
事件不会被触发,我们需要在 command 被按下时手动释放它们。致maintainers:可以用中文和我交流。