KeyboardJS
KeyboardJS copied to clipboard
bind() with preventRepeatByDefault=true omits the first firing of pressHandler
With preventRepeatByDefault=true, the first time the combo is pressed and released, only the releaseHandler is fired
Example code
keyboardJS.bind('c',
() => console.log('pressed c'),
() => console.log('released c'),
true)
https://jsfiddle.net/nzao3bdc/5/
Result press and release "c" :
"released c"
press and release "c" again :
"pressed c" "released c"
Expected behavior press and release "c" :
"pressed c" "released c"
press and release "c" again :
"pressed c" "released c"
Enviroment:
- OS: Linux
- Browser Chrome 83 , Firefox ESR
- KeyboardJS version: 2.6.2, master (970e19a2)
Proposed fix It looks like the problem is here: https://github.com/RobertWHurst/KeyboardJS/blob/master/lib/keyboard.js#L86
this._listeners.push({
keyCombo : keyComboStr ? new KeyCombo(keyComboStr) : null,
pressHandler : pressHandler || null,
releaseHandler : releaseHandler || null,
// bug here? :
preventRepeat : preventRepeatByDefault || false, // should be just false
preventRepeatByDefault: preventRepeatByDefault || false,
executingHandler : false
});
Thanks for reporting. I'll have a look.
I'm experiencing the same issue, is this going to be resolved?
It should be resolved now in the latest build