Skip to content

Commit

Permalink
Fix: 修复了无效按键会使快捷键失效的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Miaoyww authored and Steve-xmh committed Mar 23, 2024
1 parent 5e51159 commit 8e0028b
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions src/utils/keybindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,32 @@ window.addEventListener("keyup", (evt) => {
bufferedKeys.clear();
return;
}
pressingKeys.delete(evt.code);
if (pressingKeys.size === 0) {
if (bufferedKeys.size > 0) {
const joined = [...bufferedKeys].join(" + ");
bufferedKeys.clear();
const callbacks = registeredKeyBindings.get(joined);
if (callbacks) {
const downTimeOffset = evt.timeStamp - downTime;
const e: KeyBindingEvent = {
downTime,
downTimeOffset,
};
for (const cb of callbacks) {
try {
cb(e);
} catch (err) {
console.warn("Error in key binding ", joined, "callback", err);
}
console.log(pressingKeys.size);
if (bufferedKeys.size > 0) {
const joined = [...bufferedKeys].join(" + ");
bufferedKeys.clear();
const callbacks = registeredKeyBindings.get(joined);

if (callbacks) {
const downTimeOffset = evt.timeStamp - downTime;
const e: KeyBindingEvent = {
downTime,
downTimeOffset,
};
for (const cb of callbacks) {
try {
cb(e);
} catch (err) {
console.warn("Error in key binding ", joined, "callback", err);
}
evt.preventDefault();
evt.stopPropagation();
evt.stopImmediatePropagation();
}
evt.preventDefault();
evt.stopPropagation();
evt.stopImmediatePropagation();
}
}
pressingKeys.clear();

});

// From https://wangchujiang.com/hotkeys-js/
Expand Down

0 comments on commit 8e0028b

Please sign in to comment.