Skip to content
TypeScript

fix(web): keep numbered jumps from stealing browser tabs (#12315)

Yash Singh3fd5d6439d8f
diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx
index e27cc4543b5..79d393fc8d1 100644
--- a/apps/web/src/components/ChatView.tsx
+++ b/apps/web/src/components/ChatView.tsx
@@ -6652,6 +6652,8 @@ export default function ChatView(props: ChatViewProps) {
previewFocus: isPreviewFocused(),
previewOpen: previewPanelOpen,
modelPickerOpen: composerRef.current?.isModelPickerOpen() ?? false,
+ isWeb: !isElectron,
+ isDesktop: isElectron,
}),
[composerRef, previewPanelOpen, terminalUiState.terminalOpen],
);
diff --git a/apps/web/src/components/pullRequest/PullRequestDetailPanel.test.tsx b/apps/web/src/components/pullRequest/PullRequestDetailPanel.test.tsx
index 4bdf6ee7d53..18320ae3356 100644
--- a/apps/web/src/components/pullRequest/PullRequestDetailPanel.test.tsx
+++ b/apps/web/src/components/pullRequest/PullRequestDetailPanel.test.tsx
@@ -294,6 +294,8 @@ describe.each([
terminalOpen: false,
previewFocus: false,
previewOpen: false,
+ isWeb: true,
+ isDesktop: false,
})}
/>,
);
diff --git a/apps/web/src/components/settings/KeybindingsSettings.logic.test.ts b/apps/web/src/components/settings/KeybindingsSettings.logic.test.ts
index ff3b30124a7..10fc154d5b0 100644
--- a/apps/web/src/components/settings/KeybindingsSettings.logic.test.ts
+++ b/apps/web/src/components/settings/KeybindingsSettings.logic.test.ts
@@ -210,7 +210,15 @@ describe("KeybindingsSettings.logic", () => {
const options = buildWhenVariableOptions();
expect(options).toEqual(
- expect.arrayContaining(["terminalFocus", "terminalOpen", "modelPickerOpen", "true", "false"]),
+ expect.arrayContaining([
+ "terminalFocus",
+ "terminalOpen",
+ "isWeb",
+ "isDesktop",
+ "modelPickerOpen",
+ "true",
+ "false",
+ ]),
);
expect(options).not.toContain("customModeActive");
});
diff --git a/apps/web/src/components/settings/KeybindingsSettings.logic.ts b/apps/web/src/components/settings/KeybindingsSettings.logic.ts
index a910c7e5535..dc4d33bc28b 100644
--- a/apps/web/src/components/settings/KeybindingsSettings.logic.ts
+++ b/apps/web/src/components/settings/KeybindingsSettings.logic.ts
@@ -31,7 +31,14 @@ export interface KeybindingRow {
export type WhenVariableOption = string;
export type KeybindingCommandOption = KeybindingCommand;
-const CORE_WHEN_VARIABLES = ["terminalFocus", "terminalOpen", "true", "false"] as const;
+const CORE_WHEN_VARIABLES = [
+ "terminalFocus",
+ "terminalOpen",
+ "isWeb",
+ "isDesktop",
+ "true",
+ "false",
+] as const;
const DEFAULT_WHEN_VARIABLES = new Set<string>(CORE_WHEN_VARIABLES);
for (const binding of DEFAULT_RESOLVED_KEYBINDINGS) {
diff --git a/apps/web/src/keybindings.test.ts b/apps/web/src/keybindings.test.ts
index 3bec6007f70..d9c3eccbeb4 100644
--- a/apps/web/src/keybindings.test.ts
+++ b/apps/web/src/keybindings.test.ts
@@ -535,6 +535,43 @@ describe("thread navigation helpers", () => {
}),
);
});
+
+ it("keeps default thread jumps off the web so the browser can switch tabs", () => {
+ const input = event({ key: "1", metaKey: true });
+ assert.isNull(
+ resolveShortcutCommand(input, DEFAULT_RESOLVED_KEYBINDINGS, {
+ platform: "MacIntel",
+ context: { isDesktop: false },
+ }),
+ );
+ assert.strictEqual(
+ resolveShortcutCommand(input, DEFAULT_RESOLVED_KEYBINDINGS, {
+ platform: "MacIntel",
+ context: { isDesktop: true },
+ }),
+ "thread.jump.1",
+ );
+ assert.isFalse(
+ shouldShowThreadJumpHintsForModifiers(
+ event({ metaKey: true }),
+ DEFAULT_RESOLVED_KEYBINDINGS,
+ {
+ platform: "MacIntel",
+ context: { isDesktop: false },
+ },
+ ),
+ );
+ assert.isTrue(
+ shouldShowThreadJumpHintsForModifiers(
+ event({ metaKey: true }),
+ DEFAULT_RESOLVED_KEYBINDINGS,
+ {
+ platform: "MacIntel",
+ context: { isDesktop: true },
+ },
+ ),
+ );
+ });
});
describe("model picker navigation helpers", () => {
@@ -546,6 +583,30 @@ describe("model picker navigation helpers", () => {
assert.strictEqual(modelPickerJumpIndexFromCommand("modelPicker.jump.3"), 2);
assert.isNull(modelPickerJumpIndexFromCommand("thread.jump.1"));
});
+
+ it("keeps default model jumps off the web even while the picker is open", () => {
+ const input = event({ key: "3", metaKey: true });
+ assert.isNull(
+ resolveShortcutCommand(input, DEFAULT_RESOLVED_KEYBINDINGS, {
+ platform: "MacIntel",
+ context: { isDesktop: false, modelPickerOpen: true },
+ }),
+ );
+ assert.strictEqual(
+ resolveShortcutCommand(input, DEFAULT_RESOLVED_KEYBINDINGS, {
+ platform: "MacIntel",
+ context: { isDesktop: true, modelPickerOpen: true },
+ }),
+ "modelPicker.jump.3",
+ );
+ assert.strictEqual(
+ resolveShortcutCommand(input, DEFAULT_RESOLVED_KEYBINDINGS, {
+ platform: "MacIntel",
+ context: { isDesktop: true, modelPickerOpen: false },
+ }),
+ "thread.jump.3",
+ );
+ });
});
describe("chat/editor shortcuts", () => {
@@ -1106,7 +1167,7 @@ describe("composer and pull request shortcuts", () => {
}
});
- it.each(["terminalOpen", "previewFocus", "previewOpen", "modelPickerOpen"])(
+ it.each(["terminalOpen", "previewFocus", "previewOpen", "modelPickerOpen", "isWeb", "isDesktop"])(
"honors custom PR shortcut conditions for %s",
(condition) => {
const bindings = compileResolvedKeybindingsConfig([
diff --git a/apps/web/src/keybindings.ts b/apps/web/src/keybindings.ts
index 6b5556a1669..84d325c38d9 100644
--- a/apps/web/src/keybindings.ts
+++ b/apps/web/src/keybindings.ts
@@ -8,6 +8,7 @@ import {
type ModelPickerJumpKeybindingCommand,
type ThreadJumpKeybindingCommand,
} from "@t3tools/contracts";
+import { isElectron } from "./env";
import { isMacPlatform } from "./lib/utils";
export interface ShortcutEventLike {
@@ -33,6 +34,8 @@ export interface ShortcutMatchContext {
terminalOpen: boolean;
previewFocus: boolean;
previewOpen: boolean;
+ isWeb: boolean;
+ isDesktop: boolean;
[key: string]: boolean;
}
@@ -144,6 +147,8 @@ function resolveContext(options: ShortcutMatchOptions | undefined): ShortcutMatc
terminalOpen: false,
previewFocus: false,
previewOpen: false,
+ isWeb: !isElectron,
+ isDesktop: isElectron,
...options?.context,
};
}
diff --git a/apps/web/src/routes/_chat.pull-requests.tsx b/apps/web/src/routes/_chat.pull-requests.tsx
index 71829cacad2..bed2b65da5e 100644
--- a/apps/web/src/routes/_chat.pull-requests.tsx
+++ b/apps/web/src/routes/_chat.pull-requests.tsx
@@ -156,6 +156,8 @@ function getShortcutContext() {
previewFocus: false,
previewOpen: false,
modelPickerOpen: false,
+ isWeb: !isElectron,
+ isDesktop: isElectron,
};
}
diff --git a/docs/user/keybindings.md b/docs/user/keybindings.md
index f9284811de3..9c2f92a3e33 100644
--- a/docs/user/keybindings.md
+++ b/docs/user/keybindings.md
@@ -84,7 +84,14 @@ Join modifiers and a key with `+`, such as `mod+shift+d` or `ctrl+l`.
## When conditions
Available context keys are `terminalFocus`, `terminalOpen`, `previewFocus`,
-`previewOpen`, and `modelPickerOpen`. Unknown keys evaluate to `false`.
+`previewOpen`, `modelPickerOpen`, `isWeb`, and `isDesktop`. `isWeb` is true in a
+browser tab. `isDesktop` is true in the desktop app. Unknown keys evaluate to
+`false`.
+
+`mod+1` through `mod+9` jump to the first nine threads, and to models while the
+model picker is open. Those defaults use `isDesktop` so they do not steal the
+browser's tab-switch shortcuts. Remove that condition in Settings if you want
+the same jumps in a browser.
Combine keys with `!` for not, `&&` for and, `||` for or, and parentheses:
diff --git a/packages/shared/src/keybindings.ts b/packages/shared/src/keybindings.ts
index 948212a9aac..d76d4c248a9 100644
--- a/packages/shared/src/keybindings.ts
+++ b/packages/shared/src/keybindings.ts
@@ -65,11 +65,12 @@ export const DEFAULT_KEYBINDINGS: ReadonlyArray<KeybindingRule> = [
...THREAD_JUMP_KEYBINDING_COMMANDS.map((command, index) => ({
key: `mod+${index + 1}`,
command,
+ when: "isDesktop",
})),
...MODEL_PICKER_JUMP_KEYBINDING_COMMANDS.map((command, index) => ({
key: `mod+${index + 1}`,
command,
- when: "modelPickerOpen",
+ when: "modelPickerOpen && isDesktop",
})),
];
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 6feae2edd57..b9cbc23e976 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -795,7 +795,7 @@ importers:
version: link:../../packages/shared
alchemy:
specifier: 2.0.0-beta.76
- version: 2.0.0-beta.76(b3825b36417e56a486ccb5f22a7f3d7e)
+ version: 2.0.0-beta.76(197b68e0d20fdf20cf352009eca17c9f)
drizzle-orm:
specifier: 1.0.0-rc.5-ab785fc
version: 1.0.0-rc.5-ab785fc(8ab70e2706da13c78d64d8a92fef1884)
@@ -16637,7 +16637,7 @@ snapshots:
json-schema-traverse: 1.0.0
require-from-string: 2.0.2
- [email protected](b3825b36417e56a486ccb5f22a7f3d7e):
+ [email protected](197b68e0d20fdf20cf352009eca17c9f):
dependencies:
'@alchemy.run/cloudflare-runtime': 2.0.0-beta.76(@distilled.cloud/[email protected]([email protected](patch_hash=8bef799f35729cf3465eb428196f617b434a7c9f658d56acb2874d74b21b98b2)))(@effect/[email protected]([email protected])([email protected](patch_hash=8bef799f35729cf3465eb428196f617b434a7c9f658d56acb2874d74b21b98b2))([email protected]))(@effect/[email protected]([email protected])([email protected](patch_hash=8bef799f35729cf3465eb428196f617b434a7c9f658d56acb2874d74b21b98b2))([email protected])([email protected]))(@types/[email protected])(@voidzero-dev/[email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected])([email protected])([email protected]))([email protected](patch_hash=8bef799f35729cf3465eb428196f617b434a7c9f658d56acb2874d74b21b98b2))([email protected])([email protected])
'@alchemy.run/floci': 2.0.0-beta.76([email protected](patch_hash=8bef799f35729cf3465eb428196f617b434a7c9f658d56acb2874d74b21b98b2))