mirror of
https://github.com/multica-ai/multica.git
synced 2026-07-26 20:45:37 +02:00
fix(shortcuts): ignore synthetic key events without a key
Guard shortcut parsing against synthetic key events that do not expose a string key.
This commit is contained in:
@@ -98,6 +98,14 @@ describe("keyboard shortcut definitions", () => {
|
||||
expect(shortcutMatchesEvent(null, keyEvent(key, modifiers), "macos")).toBe(false);
|
||||
});
|
||||
|
||||
it("ignores synthetic events without a key, such as Chrome autofill", () => {
|
||||
const event = keyEvent(undefined as unknown as string, { metaKey: true });
|
||||
expect(shortcutFromEvent(event, "macos")).toBeNull();
|
||||
expect(
|
||||
shortcutMatchesEvent(createShortcutChord("K", { primary: true }), event, "macos"),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("formats the same semantic binding for each platform", () => {
|
||||
const shortcut = createShortcutChord("Enter", { primary: true });
|
||||
expect(formatShortcut(shortcut, "macos")).toBe("⌘↵");
|
||||
|
||||
@@ -114,6 +114,8 @@ const KEY_LABELS: Record<string, string> = {
|
||||
};
|
||||
|
||||
function eventKey(event: KeyboardEvent): string | null {
|
||||
// Synthetic events (e.g. Chrome autofill) may omit `key` entirely.
|
||||
if (typeof event.key !== "string") return null;
|
||||
if (MODIFIER_KEYS.has(event.key) || NON_ACTIONABLE_KEYS.has(event.key)) return null;
|
||||
const key = KEY_LABELS[event.key] ?? event.key;
|
||||
if (key.length === 1 && /[a-z]/i.test(key)) return key.toUpperCase();
|
||||
|
||||
Reference in New Issue
Block a user