-
Notifications
You must be signed in to change notification settings - Fork 160
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 #166: Fix over-zealous modifier flag discrepancy correction #185
Conversation
@@ -1111,17 +1111,28 @@ class AbstractKeyEventStrategy { | |||
* Synchronises the key combination history to match the modifier key flag attributes | |||
* on new key events | |||
* @param {KeyboardEvent} event - Event to check the modifier flags for | |||
* @param {String} key - Name of key that events relates to | |||
* @param {KeyEventBitmapIndex} keyEventBitmapIndex - Index of event type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Improve this parameter description
/** | ||
* When a modifier key is being released (keyup), it sets its own modifier flag | ||
* to false. (e.g. On the keyup event for Command, the metaKey attribute is false). | ||
* If this the case, we want to handle it using the main algorithm. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Expand this comment:
... and skip the reconciliation algorithm
@@ -301,7 +301,7 @@ class FocusOnlyKeyEventStrategy extends AbstractKeyEventStrategy { | |||
return true; | |||
} | |||
|
|||
const responseAction = this._howToHandleKeyDownEvent(event, | |||
const responseAction = this._howToHandleKeyEvent(event, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🐥Renamed this function to more accurately reflect its conceptual level of abstraction (it doesn't just deal with keydown
events)
this.targetElement.focus(); | ||
}); | ||
|
||
it('then simulates the cmd keypress event and the non-modifier key\'s keypress event (https://github.com/greena13/react-hotkeys/issues/166)', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Fix this test description. (Copy and paste error.)
import FocusableElement from '../support/FocusableElement'; | ||
|
||
describe('Binding to keys with simulated keypress events:', function () { | ||
context('when HotKeys has actions for a the keydown and keyup event', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Improve this context description - could be more specific.
@@ -28,26 +28,26 @@ export default class FocusableElement { | |||
} | |||
|
|||
keyDown(key, options = {}) { | |||
this.element.simulate('keyDown', {key}); | |||
this.element.simulate('keyDown', {key, ...options}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🐥 Allows passing additional KeyboardEvent
attributes when writing tests.
Context
There is a subroutine that is run on the
keyup
event that checks the currentKeyBoardEvent
's modifier key flags (e.g.metaKey
) and compares it against the key state thatreact-hotkeys
is maintaining. It then corrects for any discrepancies (missed key events, most likely due to a focus loss) in thereact-hotkeys
record of key state.On the
keyup
event for a modifier key (e.g. Command/Meta
), its own corresponding modifier key flag (e.g.metaKey
) is false. This was causing registering the key as being in thekeyup
state twice, resulting in #166 whereby handlers bound to thekeyup
event of theMeta
key were not being called.This pull request
keyup
state, and skips running the subroutine