Skip to content

Commit

Permalink
fix: Fix the bug that the window will bind multiple focus events when…
Browse files Browse the repository at this point in the history
… hotkeys is called multiple times by different element option (#347)
  • Loading branch information
zhaokun1219 authored Apr 8, 2022
1 parent 3c3a2ad commit 9145770
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { addEvent, getMods, getKeys, compareArray } from './utils';
import { _keyMap, _modifier, modifierMap, _mods, _handlers } from './var';

let _downKeys = []; // 记录摁下的绑定键

let winListendFocus = false; // window是否已经监听了focus事件
let _scope = 'all'; // 默认热键范围
const elementHasBindEvent = []; // 已绑定事件的节点记录

Expand Down Expand Up @@ -372,9 +372,12 @@ function hotkeys(key, option, method) {
addEvent(element, 'keydown', (e) => {
dispatch(e);
});
addEvent(window, 'focus', () => {
_downKeys = [];
});
if (!winListendFocus) {
winListendFocus = true;
addEvent(window, 'focus', () => {
_downKeys = [];
});
}
addEvent(element, 'keyup', (e) => {
dispatch(e);
clearModifier(e);
Expand Down

0 comments on commit 9145770

Please sign in to comment.