fix(shortcuts): prevent accidental double-Shift palette activation (#1519)

This commit is contained in:
ZacharyZcR authored and GitHub committed 2026-09-30 09:47:16 -05:00
1 parent 7d06686f62
commit cbbb80bc82
3 files changed
+121 -19

No files matched your search

+32
View File
@@ -25,3 +25,35 @@ export function dispatchCtrlW(target: EventTarget | null) {
});
return !target.dispatchEvent(event);
}
/** Match two consecutive Shift presses, never a typing or IME sequence. */
export function createCommandPaletteShortcutMatcher() {
let lastShift: number | null = null;
const reset = () => {
lastShift = null;
};
const matches = (event: KeyboardEvent, now = Date.now()): boolean => {
if (
event.defaultPrevented ||
event.isComposing ||
event.keyCode === 229 ||
event.repeat ||
event.altKey
) {
reset();
return false;
}
if (isShiftKey(event) && !event.ctrlKey && !event.metaKey) {
const matched = lastShift !== null && now - lastShift < 300;
lastShift = matched ? null : now;
return matched;
}
reset();
return (
(event.ctrlKey || event.metaKey) &&
!event.shiftKey &&
event.code === "KeyK"
);
};
return { matches, reset };
}