KeyboardJS icon indicating copy to clipboard operation
KeyboardJS copied to clipboard

bind() with preventRepeatByDefault=true omits the first firing of pressHandler

Open jonathanwin opened this issue 3 years ago • 1 comments

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
    });

jonathanwin avatar Jul 30 '20 16:07 jonathanwin

Thanks for reporting. I'll have a look.

RobertWHurst avatar Aug 08 '20 00:08 RobertWHurst

I'm experiencing the same issue, is this going to be resolved?

utiq avatar Aug 09 '22 01:08 utiq

It should be resolved now in the latest build

RobertWHurst avatar Aug 27 '22 17:08 RobertWHurst