jaywcjlove / hotkeys-js

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

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

Closed cangSDARM closed 10 months ago

cangSDARM commented 10 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 10 months ago

@cangSDARM Upgrade v3.13.2