Skip to content

Commit ae1e89e

Browse files
MarcoDotIOclaude
andauthored
fix(desktop): SnapShot shortcuts with arrow keys register on macOS and Windows (#22934)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent e492686 commit ae1e89e

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

‎apps/desktop/src/snapShot/snapShot.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { it as effectIt } from "@effect/vitest";
22
import * as HostProcess from "@t3tools/shared/HostProcess";
3+
import { parseKeybindingShortcut } from "@t3tools/shared/keybindings";
34
import * as Effect from "effect/Effect";
45
import { describe, expect, it } from "vite-plus/test";
56

@@ -9,6 +10,7 @@ import {
910
compactAccessibilityTree,
1011
findAccessibleWindow,
1112
isWaylandSession,
13+
toElectronAccelerator,
1214
} from "./snapShot.ts";
1315

1416
describe("accessibleWindowText", () => {
@@ -448,6 +450,21 @@ describe("findAccessibleWindow", () => {
448450
});
449451
});
450452

453+
describe("toElectronAccelerator", () => {
454+
// The settings recorder stores shortcuts through parseKeybindingShortcut, which lowercases keys.
455+
it.each([
456+
["mod+shift+arrowup", "CommandOrControl+Shift+Up"],
457+
["mod+shift+arrowdown", "CommandOrControl+Shift+Down"],
458+
["ctrl+alt+arrowleft", "Control+Alt+Left"],
459+
["ctrl+alt+arrowright", "Control+Alt+Right"],
460+
["mod+shift+esc", "CommandOrControl+Shift+Esc"],
461+
["mod+shift+space", "CommandOrControl+Shift+Space"],
462+
["mod+shift+2", "CommandOrControl+Shift+2"],
463+
])("maps a recorded %s to an Electron accelerator", (recorded, accelerator) => {
464+
expect(toElectronAccelerator(parseKeybindingShortcut(recorded)!)).toBe(accelerator);
465+
});
466+
});
467+
451468
describe("isWaylandSession", () => {
452469
effectIt.effect(
453470
"falls back to a live runtime directory socket when session variables are stripped",

‎apps/desktop/src/snapShot/snapShot.ts‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -539,14 +539,15 @@ function findBrowserTitleMatch<T extends { readonly name?: string | null }>(
539539
return browserMatches.length === 1 ? browserMatches[0] : undefined;
540540
}
541541

542+
// Keyed by the lowercase tokens parseKeybindingShortcut stores; Electron has no `ArrowUp` token.
542543
const ELECTRON_KEY_NAMES: Readonly<Record<string, string>> = {
543544
" ": "Space",
544545
"+": "Plus",
545-
ArrowDown: "Down",
546-
ArrowLeft: "Left",
547-
ArrowRight: "Right",
548-
ArrowUp: "Up",
549-
Escape: "Esc",
546+
arrowdown: "Down",
547+
arrowleft: "Left",
548+
arrowright: "Right",
549+
arrowup: "Up",
550+
escape: "Esc",
550551
};
551552

552553
export function sameSnapShotShortcut(left: SnapShotShortcut, right: SnapShotShortcut): boolean {

0 commit comments

Comments
 (0)