| author | |
| committer | |
| log | f864ef189d5def4cb2ae3f34cc461f13b3fc5a00 |
| tree | 16da86ed68283ca70a1a1019af82a6d92be57abe |
| parent | 765f4cd00bb05b4111f1279a8dac47b36665fccd |
- guard terminal clear/navigation shortcut handlers to only process `keydown`
- add tests verifying `keyup` events are ignored2 files changed, 22 insertions(+), 0 deletions(-)
apps/web/src/keybindings.test.ts+13| ... | ... | @@ -325,6 +325,10 @@ describe("isTerminalClearShortcut", () => { |
| 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", () => { |
| 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", () => { |
apps/web/src/keybindings.ts+9| ... | ... | @@ -7,6 +7,7 @@ import { |
| 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( |
| 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( |
| 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); |