ngneat/hotkeys

Cannot define keyup handlers for hotkeys that have keydown handlers defined.

solkaz opened this issue · 2 comments

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

I cannot write the following without getting a warning:

this.hotkeys
      .addShortcut({ keys: 'space' })
      .pipe(untilDestroyed(this))
      .subscribe(()=> this.onSpaceKeyDown());

this.hotkeys
      .addShortcut({ keys: 'space', trigger: 'keyup' })
      .pipe(untilDestroyed(this))
      .subscribe(()=> this.onSpaceKeyUp());

The warning:

Duplicated shortcut

Expected behavior

I should be able to write the above code snippet without getting a warning.

This may be a mis-understanding on my part, as I thought that my scenario shouldn't be considered a duplicate key (while it is referring to the same key, it's for different events). If my assumption isn't correct, then maybe the FAQs need to be updated.

Minimal reproduction of the problem with instructions

https://github.com/solkaz/ngneat-hotkeys-issue/

What is the motivation / use case for changing the behavior?

Being able to define a "keyup" handler for a hotkey that already has a "keydown" handler defined.

Environment


Angular version: X.Y.Z


Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
Others:

N/A

Yes, it's the same shortcut. Think about what you'd show in the helper modal.

Internally, only the key combination is being checked to determine whether the shortcut is a duplicate or not. As @NetanelBasal pointed out, two shortcuts, that use the same key combination, are the same regardless which trigger you use.