diff --git a/apps/web/src/keybindings.test.ts b/apps/web/src/keybindings.test.ts index a3c88dbd9194f0e142e04cd67f47f19f0a5f9617..4ceb1b920ac8fc780477032c217513d3fcc37175 100644 --- a/apps/web/src/keybindings.test.ts +++ b/apps/web/src/keybindings.test.ts @@ -325,6 +325,10 @@ describe("isTerminalClearShortcut", () => { it("matches Cmd+K on macOS", () => { assert.isTrue(isTerminalClearShortcut(event({ key: "k", metaKey: true }), "MacIntel")); }); + + it("ignores non-keydown events", () => { + assert.isFalse(isTerminalClearShortcut(event({ type: "keyup", key: "l", ctrlKey: true }), "Linux")); + }); }); describe("terminalNavigationShortcutData", () => { @@ -371,6 +375,15 @@ describe("terminalNavigationShortcutData", () => { assert.isNull(terminalNavigationShortcutData(event({ key: "ArrowLeft", metaKey: true }), "Linux")); assert.isNull(terminalNavigationShortcutData(event({ key: "a", altKey: true }), "MacIntel")); }); + + it("ignores non-keydown events", () => { + assert.isNull( + terminalNavigationShortcutData( + event({ type: "keyup", key: "ArrowLeft", altKey: true }), + "MacIntel", + ), + ); + }); }); describe("plus key parsing", () => { diff --git a/apps/web/src/keybindings.ts b/apps/web/src/keybindings.ts index 8b7fed6e1dce039db181579df06e1a005f374aa6..4efcd6fee399372b7230c508e6d47e257796a031 100644 --- a/apps/web/src/keybindings.ts +++ b/apps/web/src/keybindings.ts @@ -7,6 +7,7 @@ import { import { isMacPlatform } from "./lib/utils"; export interface ShortcutEventLike { + type?: string; key: string; metaKey: boolean; ctrlKey: boolean; @@ -209,6 +210,10 @@ export function isTerminalClearShortcut( event: ShortcutEventLike, platform = navigator.platform, ): boolean { + if (event.type !== undefined && event.type !== "keydown") { + return false; + } + const key = event.key.toLowerCase(); if (key === "l" && event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey) { @@ -229,6 +234,10 @@ export function terminalNavigationShortcutData( event: ShortcutEventLike, platform = navigator.platform, ): string | null { + if (event.type !== undefined && event.type !== "keydown") { + return null; + } + if (event.shiftKey) return null; const key = normalizeEventKey(event.key);