jaywcjlove / hotkeys-js

➷ A robust Javascript library for capturing keyboard input. It has no dependencies.
https://jaywcjlove.github.io/hotkeys-js
MIT License
6.69k stars 413 forks source link

fix: `single` config will conflict with other combinations #465

Closed cangSDARM closed 11 months ago

cangSDARM commented 11 months ago

抱歉,之前没有仔细查看源码,写的有问题。没有注意到_handlers是per key的

导致一种情况:

    hotkeys('ctrl+s', { single: true }, (e) => {
      expect(e.keyCode).toBe(83);
      expect(e.ctrlKey).toBeTruthy();
    });
    hotkeys('ctrl+shift+s', { single: true }, (e) => {
      expect(e.shiftKey).toBeTruthy();
      expect(e.keyCode).toBe(83);
      expect(e.ctrlKey).toBeTruthy();
    });

ctrl+s不会触发,只会触发后绑定的ctrl+shift+s (因为s重复。ctrl是特殊键不算重复)

这次修复了这个问题 (不会重置 _handlers,而是内部调用 unbind),顺便加了对应的test

jaywcjlove commented 11 months ago

@cangSDARM Upgrade v3.13.2