From b7bbcb205409bc0b4855f1b825941de99dd2e461 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 15 Feb 2026 17:02:38 -0800 Subject: [PATCH] Ignore non-keydown terminal shortcuts - guard terminal clear/navigation shortcut handlers to only process `keydown` - add tests verifying `keyup` events are ignored --- apps/web/src/keybindings.test.ts | 13 +++++++++++++ apps/web/src/keybindings.ts | 9 +++++++++ 2 files changed, 22 insertions(+) diff --git a/apps/web/src/keybindings.test.ts b/apps/web/src/keybindings.test.ts index a3c88dbd91..4ceb1b920a 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 8b7fed6e1d..4efcd6fee3 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);