fix: Fix the bug that the window will bind multiple focus events when hotkeys is called multiple times by different element option (#347)

pull/338/head
zhaokun1219 3 years ago committed by GitHub
parent 3c3a2ade1e
commit 9145770285
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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 = []; // 已绑定事件的节点记录
@ -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);

Loading…
Cancel
Save