fix(web): hotkey settings record plain keys and Tab (#14548)

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
Theo BrowneandClaude Opus 5.5 authored and GitHub committed 2026-09-30 23:40:17 -07:00
1 parent 921cb3c8bc
commit 71a90ae70e
4 files changed
+32 -5

No files matched your search

@@ -113,6 +113,31 @@ describe("KeybindingsSettings.logic", () => {
).toBe("mod+shift+k");
});
it.each([
["k", "KeyK", "k"],
["Tab", "Tab", "tab"],
["F5", "F5", "f5"],
])("captures %s without a modifier", (key, code, expected) => {
const noModifiers = { metaKey: false, ctrlKey: false, altKey: false, shiftKey: false };
expect(keybindingFromKeyboardEvent({ key, code, ...noModifiers }, "MacIntel")).toBe(expected);
});
it("waits for a key when only a modifier is pressed", () => {
expect(
keybindingFromKeyboardEvent(
{
key: "Meta",
code: "MetaLeft",
metaKey: true,
ctrlKey: false,
altKey: false,
shiftKey: false,
},
"MacIntel",
),
).toBeNull();
});
it.each([
["@", "Digit2", "mod+shift+2"],
['"', "Digit2", "mod+shift+2"],
@@ -358,6 +358,7 @@ function normalizeShortcutKeyToken(key: string): string | null {
return null;
}
/** Turns a keydown into a binding such as `mod+shift+k` or `tab`. Null for modifier-only presses. */
export function keybindingFromKeyboardEvent(
event: Pick<KeyboardEvent, "key" | "code" | "metaKey" | "ctrlKey" | "altKey" | "shiftKey">,
platform: string,
@@ -375,9 +376,6 @@ export function keybindingFromKeyboardEvent(
}
if (event.altKey) parts.push("alt");
if (event.shiftKey) parts.push("shift");
if (parts.length === 0) {
return null;
}
parts.push(keyToken);
return parts.join("+");
}
@@ -768,7 +768,8 @@ function useKeybindingRowEditor({
};
const captureKeybinding = (event: KeyboardEvent<HTMLInputElement>) => {
if (event.key === "Tab") return;
// Tab is recorded like any key while recording; after that it moves focus on.
if (event.key === "Tab" && !isRecording) return;
event.preventDefault();
if (event.key === "Escape") {
setDraft({ keyDraft: row.key, isRecording: false });
@@ -1083,7 +1084,8 @@ function useNewKeybindingDraft({
};
const captureKeybinding = (event: KeyboardEvent<HTMLInputElement>) => {
if (event.key === "Tab") return;
// Tab is recorded like any key while recording; after that it moves focus on.
if (event.key === "Tab" && !isRecording) return;
event.preventDefault();
if (event.key === "Escape") {
setDraft({ keyDraft: "", isRecording: false });
@@ -106,6 +106,8 @@ export function useSnapShotShortcutRecorder({
}
return;
}
// A global shortcut without a modifier would take that key from every app.
if (!event.metaKey && !event.ctrlKey && !event.altKey && !event.shiftKey) return;
const input = keybindingFromKeyboardEvent(event, navigator.platform);
if (!input) return;
const next = parseKeybindingShortcut(input);