fix: Trigger shortcut key when keyup (#410)
This commit is contained in:
@@ -61,14 +61,25 @@ export const shortcutRegister = (targetKeys = [], fn, target = document) => {
|
||||
if (targetKeys.length === 0) return () => {};
|
||||
|
||||
const targetKeySet = new Set(targetKeys);
|
||||
let hasInterference = false;
|
||||
const onKeyDown = (pressedKeys, event) => {
|
||||
if (isSameSet(targetKeySet, pressedKeys)) {
|
||||
// event.preventDefault(); // 阻止浏览器的默认行为
|
||||
// event.stopPropagation(); // 阻止事件继续(向父元素)冒泡
|
||||
fn();
|
||||
// if (isSameSet(targetKeySet, pressedKeys)) {
|
||||
// // event.preventDefault(); // 阻止浏览器的默认行为
|
||||
// // event.stopPropagation(); // 阻止事件继续(向父元素)冒泡
|
||||
// fn();
|
||||
// }
|
||||
if (!targetKeySet.has(event.code)) {
|
||||
hasInterference = true;
|
||||
}
|
||||
};
|
||||
const onKeyUp = (pressedKeys, event) => {
|
||||
if (isSameSet(targetKeySet, pressedKeys) && !hasInterference) {
|
||||
fn();
|
||||
}
|
||||
if (pressedKeys.size === 1) {
|
||||
hasInterference = false;
|
||||
}
|
||||
};
|
||||
const onKeyUp = () => {};
|
||||
|
||||
return shortcutListener(onKeyDown, onKeyUp, target);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user