* Fix shortcut capture ignoring - = ; ' keys KEY_MAP was missing Minus/Equal/Semicolon/Quote, so keyboardEventToComboString returned null for those physical keys and the capture UI silently dropped them. Add the four entries with their shifted variants. Also suppress the Electron View > Zoom accelerators (Cmd+-/=/0) while capturing, so those combos reach the renderer instead of zooming the window. Driven by the existing capturingShortcut flag via a new paseo:menu:set-capturing-shortcut IPC. * fix: address review feedback from PR #2047 Trim the capturing useEffect so it only fires when capture is active (removes the redundant on-mount false and the double-fire on true->false), and reset the main-process capturingShortcut flag on renderer reload via browser-window-created + did-finish-load so a Cmd+R mid-capture can't leave the zoom accelerators disabled. --------- Co-authored-by: Mohamed Boudra <boudra.moha@gmail.com>
71 lines
2.2 KiB
TypeScript
71 lines
2.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
keyComboToString,
|
|
keyboardEventToComboString,
|
|
parseShortcutString,
|
|
} from "./shortcut-string";
|
|
|
|
function keyboardEvent(overrides: Partial<KeyboardEvent>): KeyboardEvent {
|
|
return {
|
|
key: "",
|
|
code: "",
|
|
altKey: false,
|
|
ctrlKey: false,
|
|
metaKey: false,
|
|
shiftKey: false,
|
|
repeat: false,
|
|
...overrides,
|
|
} as KeyboardEvent;
|
|
}
|
|
|
|
describe("keyboardEventToComboString", () => {
|
|
it("captures the minus key (regression: previously returned null)", () => {
|
|
expect(keyboardEventToComboString(keyboardEvent({ key: "-", code: "Minus" }))).toBe("-");
|
|
});
|
|
|
|
it("captures minus with modifiers", () => {
|
|
expect(
|
|
keyboardEventToComboString(keyboardEvent({ key: "-", code: "Minus", metaKey: true })),
|
|
).toBe("Cmd+-");
|
|
expect(
|
|
keyboardEventToComboString(keyboardEvent({ key: "_", code: "Minus", shiftKey: true })),
|
|
).toBe("Shift+-");
|
|
});
|
|
|
|
it("captures equal, semicolon, and quote", () => {
|
|
expect(keyboardEventToComboString(keyboardEvent({ key: "=", code: "Equal" }))).toBe("=");
|
|
expect(keyboardEventToComboString(keyboardEvent({ key: ";", code: "Semicolon" }))).toBe(";");
|
|
expect(keyboardEventToComboString(keyboardEvent({ key: "'", code: "Quote" }))).toBe("'");
|
|
});
|
|
|
|
it("still returns null for modifier-only presses", () => {
|
|
expect(keyboardEventToComboString(keyboardEvent({ code: "ShiftLeft" }))).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("parseShortcutString round-trips punctuation keys", () => {
|
|
const cases: ReadonlyArray<[string, string, string, string]> = [
|
|
["-", "Minus", "-", "_"],
|
|
["=", "Equal", "=", "+"],
|
|
[";", "Semicolon", ";", ":"],
|
|
["'", "Quote", "'", '"'],
|
|
];
|
|
|
|
for (const [humanKey, code, key, shiftedKey] of cases) {
|
|
it(`round-trips ${humanKey}`, () => {
|
|
const combo = parseShortcutString(humanKey);
|
|
expect(combo.code).toBe(code);
|
|
expect(combo.key).toBe(key);
|
|
expect(combo.shiftedKey).toBe(shiftedKey);
|
|
expect(keyComboToString(combo)).toBe(humanKey);
|
|
});
|
|
}
|
|
|
|
it("round-trips a modifier combo with minus", () => {
|
|
const combo = parseShortcutString("Cmd+-");
|
|
expect(combo.meta).toBe(true);
|
|
expect(combo.code).toBe("Minus");
|
|
expect(keyComboToString(combo)).toBe("Cmd+-");
|
|
});
|
|
});
|