Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions apps/desktop/src/snapShot/snapShot.test.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -9,6 +10,7 @@ import {
compactAccessibilityTree,
findAccessibleWindow,
isWaylandSession,
toElectronAccelerator,
} from "./snapShot.ts";

describe("accessibleWindowText", () => {
Expand Down Expand Up @@ -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",
Expand Down
11 changes: 6 additions & 5 deletions apps/desktop/src/snapShot/snapShot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading