Skip to content

Commit 06ad134

Browse files
committed
fix(web): avoid desktop and AltGr shortcut conflicts
1 parent 4e5348d commit 06ad134

4 files changed

Lines changed: 57 additions & 4 deletions

File tree

‎apps/web/src/keybindings.test.ts‎

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,12 +1067,12 @@ describe("composer control shortcuts", () => {
10671067
["h", "composer.host", true],
10681068
["e", "composer.effort", false],
10691069
["a", "composer.mode", false],
1070-
["t", "composer.workspace", false],
1070+
["s", "composer.workspace", false],
10711071
["g", "composer.branch", false],
10721072
["p", "composer.previousWorktree", false],
10731073
] as const;
10741074

1075-
for (const platform of ["MacIntel", "Linux"]) {
1075+
for (const platform of ["MacIntel", "Win32", "Linux"]) {
10761076
it.each(shortcuts)(
10771077
`resolves %s on ${platform} and leaves terminal input alone`,
10781078
(key, command, shiftKey) => {
@@ -1100,6 +1100,47 @@ describe("composer control shortcuts", () => {
11001100
);
11011101
}
11021102

1103+
it("leaves AltGr text entry alone on Windows and Linux", () => {
1104+
for (const platform of ["Win32", "Linux"]) {
1105+
const input = event({
1106+
key: "€",
1107+
code: "KeyE",
1108+
ctrlKey: true,
1109+
altKey: true,
1110+
getModifierState: (key) => key === "AltGraph",
1111+
});
1112+
assert.isNull(resolveShortcutCommand(input, DEFAULT_RESOLVED_KEYBINDINGS, { platform }));
1113+
assert.strictEqual(
1114+
resolveShortcutCommand(
1115+
{ ...input, getModifierState: () => false },
1116+
DEFAULT_RESOLVED_KEYBINDINGS,
1117+
{ platform },
1118+
),
1119+
"composer.effort",
1120+
);
1121+
}
1122+
});
1123+
1124+
it("keeps Firefox modifier reporting usable on Windows and macOS", () => {
1125+
const getModifierState = (key: string) => key === "AltGraph";
1126+
assert.strictEqual(
1127+
resolveShortcutCommand(
1128+
event({ key: "e", ctrlKey: true, altKey: true, getModifierState }),
1129+
DEFAULT_RESOLVED_KEYBINDINGS,
1130+
{ platform: "Win32" },
1131+
),
1132+
"composer.effort",
1133+
);
1134+
assert.strictEqual(
1135+
resolveShortcutCommand(
1136+
event({ key: "´", code: "KeyE", metaKey: true, altKey: true, getModifierState }),
1137+
DEFAULT_RESOLVED_KEYBINDINGS,
1138+
{ platform: "MacIntel" },
1139+
),
1140+
"composer.effort",
1141+
);
1142+
});
1143+
11031144
it.each(shortcuts)("uses a custom binding for %s", (_key, command) => {
11041145
const bindings = compileResolvedKeybindingsConfig([
11051146
{ key: "mod+shift+y", command, when: "!terminalFocus" },

‎apps/web/src/keybindings.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
import { isMacPlatform } from "./lib/utils";
1212

1313
export interface ShortcutEventLike {
14+
getModifierState?: (key: "AltGraph") => boolean;
1415
type?: string;
1516
code?: string;
1617
key: string;
@@ -123,6 +124,12 @@ function matchesShortcut(
123124
shortcut: KeybindingShortcut,
124125
platform = navigator.platform,
125126
): boolean {
127+
if (
128+
!isMacPlatform(platform) &&
129+
event.getModifierState?.("AltGraph") &&
130+
!/^[a-z0-9]$/i.test(event.key)
131+
)
132+
return false;
126133
if (!matchesShortcutModifiers(event, shortcut, platform)) return false;
127134
return resolveEventKeys(event).has(shortcut.key);
128135
}

‎docs/user/keybindings.md‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ also lists the command IDs and defaults available in your version.
66
## Composer controls
77

88
Use `mod+shift+m` to choose a model and `mod+shift+h` to choose a host.
9-
Use `mod+alt+e` for effort, `mod+alt+a` for access mode, `mod+alt+t` for the
9+
Use `mod+alt+e` for effort, `mod+alt+a` for access mode, `mod+alt+s` for the
1010
workspace, and `mod+alt+g` for the Git branch. The workspace menu includes the
1111
current checkout, a new worktree, and the previous worktree when available.
1212
Use `mod+alt+p` to reuse the previous worktree directly.
@@ -16,6 +16,11 @@ the provider list. Use Up/Down to move and Enter to choose. Right returns to
1616
model search. `alt+up` and `alt+down` switch providers directly and clear the
1717
search. These provider shortcuts can also be changed in Settings.
1818

19+
These shortcuts run inside the focused web or desktop client. `mod` uses Command
20+
on macOS and Ctrl on Windows and Linux, including GNOME, KDE Plasma, Niri, and
21+
Hyprland. If a custom desktop shortcut takes the same keys, choose another binding
22+
in Settings.
23+
1924
## Edit the configuration file
2025

2126
Keybindings live on the environment's machine, in

‎packages/shared/src/keybindings.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const DEFAULT_KEYBINDINGS: ReadonlyArray<KeybindingRule> = [
4747
{ key: "mod+shift+h", command: "composer.host", when: "!terminalFocus" },
4848
{ key: "mod+alt+e", command: "composer.effort", when: "!terminalFocus" },
4949
{ key: "mod+alt+a", command: "composer.mode", when: "!terminalFocus" },
50-
{ key: "mod+alt+t", command: "composer.workspace", when: "!terminalFocus" },
50+
{ key: "mod+alt+s", command: "composer.workspace", when: "!terminalFocus" },
5151
{ key: "mod+alt+g", command: "composer.branch", when: "!terminalFocus" },
5252
{ key: "mod+alt+p", command: "composer.previousWorktree", when: "!terminalFocus" },
5353
{ key: "alt+arrowup", command: "modelPicker.previousProvider", when: "modelPickerOpen" },

0 commit comments

Comments
 (0)