Guard global shortcut key handling

This commit is contained in:
taohe
2026-06-11 13:57:56 +08:00
parent c4368c9018
commit c966eb71a7
2 changed files with 69 additions and 2 deletions
+8 -2
View File
@@ -19,16 +19,22 @@ interface Shortcut {
export function useGlobalShortcuts(shortcuts: Shortcut[]) {
useEffect(() => {
function handleKeyDown(event: KeyboardEvent) {
if (typeof event.key !== "string" || event.key.length === 0) {
return;
}
const meta = event.metaKey || event.ctrlKey;
const eventKey = event.key.toLowerCase();
for (const shortcut of shortcuts) {
const shortcutKey = shortcut.key.toLowerCase();
if (
event.key.toLowerCase() === shortcut.key.toLowerCase() &&
eventKey === shortcutKey &&
meta === shortcut.meta &&
(shortcut.shift ?? false) === event.shiftKey
) {
// Allow Cmd+K even in inputs (standard command palette behavior)
if (shortcut.key !== "k") {
if (shortcutKey !== "k") {
const target = event.target as HTMLElement;
const tag = target.tagName;
if (