- guard terminal clear/navigation shortcut handlers to only process `keydown` - add tests verifying `keyup` events are ignored
Unified · Split
| @@ -325,6 +325,10 @@ describe("isTerminalClearShortcut", () => { · 324 unmodified lines | ||
| 325 | 325 | it("matches Cmd+K on macOS", () => { |
| 326 | 326 | assert.isTrue(isTerminalClearShortcut(event({ key: "k", metaKey: true }), "MacIntel")); |
| 327 | 327 | }); |
| 328 | + | |
| 329 | + it("ignores non-keydown events", () => { | |
| 330 | + assert.isFalse(isTerminalClearShortcut(event({ type: "keyup", key: "l", ctrlKey: true }), "Linux")); | |
| 331 | + }); | |
| 328 | 332 | }); |
| 329 | 333 | |
| 330 | 334 | describe("terminalNavigationShortcutData", () => { |
| @@ -371,6 +375,15 @@ describe("terminalNavigationShortcutData", () => { · 40 unmodified lines | ||
| 371 | 375 | assert.isNull(terminalNavigationShortcutData(event({ key: "ArrowLeft", metaKey: true }), "Linux")); |
| 372 | 376 | assert.isNull(terminalNavigationShortcutData(event({ key: "a", altKey: true }), "MacIntel")); |
| 373 | 377 | }); |
| 378 | + | |
| 379 | + it("ignores non-keydown events", () => { | |
| 380 | + assert.isNull( | |
| 381 | + terminalNavigationShortcutData( | |
| 382 | + event({ type: "keyup", key: "ArrowLeft", altKey: true }), | |
| 383 | + "MacIntel", | |
| 384 | + ), | |
| 385 | + ); | |
| 386 | + }); | |
| 374 | 387 | }); |
| 375 | 388 | |
| 376 | 389 | describe("plus key parsing", () => { |
| @@ -7,6 +7,7 @@ import { · 6 unmodified lines | ||
| 7 | 7 | import { isMacPlatform } from "./lib/utils"; |
| 8 | 8 | |
| 9 | 9 | export interface ShortcutEventLike { |
| 10 | + type?: string; | |
| 10 | 11 | key: string; |
| 11 | 12 | metaKey: boolean; |
| 12 | 13 | ctrlKey: boolean; |
| @@ -209,6 +210,10 @@ export function isTerminalClearShortcut( · 196 unmodified lines | ||
| 209 | 210 | event: ShortcutEventLike, |
| 210 | 211 | platform = navigator.platform, |
| 211 | 212 | ): boolean { |
| 213 | + if (event.type !== undefined && event.type !== "keydown") { | |
| 214 | + return false; | |
| 215 | + } | |
| 216 | + | |
| 212 | 217 | const key = event.key.toLowerCase(); |
| 213 | 218 | |
| 214 | 219 | if (key === "l" && event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey) { |
| @@ -229,6 +234,10 @@ export function terminalNavigationShortcutData( · 14 unmodified lines | ||
| 229 | 234 | event: ShortcutEventLike, |
| 230 | 235 | platform = navigator.platform, |
| 231 | 236 | ): string | null { |
| 237 | + if (event.type !== undefined && event.type !== "keydown") { | |
| 238 | + return null; | |
| 239 | + } | |
| 240 | + | |
| 232 | 241 | if (event.shiftKey) return null; |
| 233 | 242 | |
| 234 | 243 | const key = normalizeEventKey(event.key); |