TypeScript
fix(desktop): SnapShot shortcuts with arrow keys register on macOS and Windows (#22934)
MarcoDotIOae1e89e6ba7e
diff --git a/apps/desktop/src/snapShot/snapShot.test.ts b/apps/desktop/src/snapShot/snapShot.test.tsindex 7c63a8b9aad..fe166f5d099 100644--- a/apps/desktop/src/snapShot/snapShot.test.ts+++ b/apps/desktop/src/snapShot/snapShot.test.ts@@ -1,5 +1,6 @@import { it as effectIt } from "@effect/vitest";import * as HostProcess from "@t3tools/shared/HostProcess";+import { parseKeybindingShortcut } from "@t3tools/shared/keybindings";import * as Effect from "effect/Effect";import { describe, expect, it } from "vite-plus/test";@@ -9,6 +10,7 @@ import {compactAccessibilityTree,findAccessibleWindow,isWaylandSession,+ toElectronAccelerator,} from "./snapShot.ts";describe("accessibleWindowText", () => {@@ -448,6 +450,21 @@ describe("findAccessibleWindow", () => {});});+describe("toElectronAccelerator", () => {+ // The settings recorder stores shortcuts through parseKeybindingShortcut, which lowercases keys.+ it.each([+ ["mod+shift+arrowup", "CommandOrControl+Shift+Up"],+ ["mod+shift+arrowdown", "CommandOrControl+Shift+Down"],+ ["ctrl+alt+arrowleft", "Control+Alt+Left"],+ ["ctrl+alt+arrowright", "Control+Alt+Right"],+ ["mod+shift+esc", "CommandOrControl+Shift+Esc"],+ ["mod+shift+space", "CommandOrControl+Shift+Space"],+ ["mod+shift+2", "CommandOrControl+Shift+2"],+ ])("maps a recorded %s to an Electron accelerator", (recorded, accelerator) => {+ expect(toElectronAccelerator(parseKeybindingShortcut(recorded)!)).toBe(accelerator);+ });+});+describe("isWaylandSession", () => {effectIt.effect("falls back to a live runtime directory socket when session variables are stripped",diff --git a/apps/desktop/src/snapShot/snapShot.ts b/apps/desktop/src/snapShot/snapShot.tsindex 872f99e1d6a..8be137cb32a 100644--- a/apps/desktop/src/snapShot/snapShot.ts+++ b/apps/desktop/src/snapShot/snapShot.ts@@ -539,14 +539,15 @@ function findBrowserTitleMatch<T extends { readonly name?: string | null }>(return browserMatches.length === 1 ? browserMatches[0] : undefined;}+// Keyed by the lowercase tokens parseKeybindingShortcut stores; Electron has no `ArrowUp` token.const ELECTRON_KEY_NAMES: Readonly<Record<string, string>> = {" ": "Space","+": "Plus",- ArrowDown: "Down",- ArrowLeft: "Left",- ArrowRight: "Right",- ArrowUp: "Up",- Escape: "Esc",+ arrowdown: "Down",+ arrowleft: "Left",+ arrowright: "Right",+ arrowup: "Up",+ escape: "Esc",};export function sameSnapShotShortcut(left: SnapShotShortcut, right: SnapShotShortcut): boolean {