Skip to content

Commit 010d015

Browse files
MarcoDotIOclaude
andcommitted
fix(desktop): SnapShot shortcuts with arrow keys register on macOS and Windows
Recorded shortcuts store lowercase keys ("arrowup"), but the Electron accelerator map was keyed by "ArrowUp", so the lookup missed and the accelerator became "ARROWUP", a token Electron does not accept. Key the map by the stored lowercase tokens. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 680152e commit 010d015

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

@@ -11,6 +12,7 @@ import {
1112
findCaptureSource,
1213
hideAndWaitForBlur,
1314
isWaylandSession,
15+
toElectronAccelerator,
1416
} from "./snapShot.ts";
1517

1618
describe("accessibleWindowText", () => {
@@ -512,6 +514,21 @@ describe("findCaptureSource", () => {
512514
});
513515
});
514516

517+
describe("toElectronAccelerator", () => {
518+
// The settings recorder stores shortcuts through parseKeybindingShortcut, which lowercases keys.
519+
it.each([
520+
["mod+shift+arrowup", "CommandOrControl+Shift+Up"],
521+
["mod+shift+arrowdown", "CommandOrControl+Shift+Down"],
522+
["ctrl+alt+arrowleft", "Control+Alt+Left"],
523+
["ctrl+alt+arrowright", "Control+Alt+Right"],
524+
["mod+shift+esc", "CommandOrControl+Shift+Esc"],
525+
["mod+shift+space", "CommandOrControl+Shift+Space"],
526+
["mod+shift+2", "CommandOrControl+Shift+2"],
527+
])("maps a recorded %s to an Electron accelerator", (recorded, accelerator) => {
528+
expect(toElectronAccelerator(parseKeybindingShortcut(recorded)!)).toBe(accelerator);
529+
});
530+
});
531+
515532
describe("isWaylandSession", () => {
516533
effectIt.effect(
517534
"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
@@ -560,14 +560,15 @@ function findBrowserTitleMatch<T extends { readonly name?: string | null }>(
560560
return browserMatches.length === 1 ? browserMatches[0] : undefined;
561561
}
562562

563+
// Keyed by the lowercase tokens parseKeybindingShortcut stores; Electron has no `ArrowUp` token.
563564
const ELECTRON_KEY_NAMES: Readonly<Record<string, string>> = {
564565
" ": "Space",
565566
"+": "Plus",
566-
ArrowDown: "Down",
567-
ArrowLeft: "Left",
568-
ArrowRight: "Right",
569-
ArrowUp: "Up",
570-
Escape: "Esc",
567+
arrowdown: "Down",
568+
arrowleft: "Left",
569+
arrowright: "Right",
570+
arrowup: "Up",
571+
escape: "Esc",
571572
};
572573

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

0 commit comments

Comments
 (0)