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

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Yash SinghandCursor authored and GitHub committed 2026-09-17 19:43:03 -05:00
1 parent 9051ed9c39
commit 3fd5d6439d
10 files changed
+102 -7

No files matched your search

+2
View File
@@ -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],
);
@@ -294,6 +294,8 @@ describe.each([
terminalOpen: false,
previewFocus: false,
previewOpen: false,
isWeb: true,
isDesktop: false,
})}
/>,
);
@@ -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");
});
@@ -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) {
+62 -1
View File
@@ -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([
+5
View File
@@ -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,
};
}
@@ -156,6 +156,8 @@ function getShortcutContext() {
previewFocus: false,
previewOpen: false,
modelPickerOpen: false,
isWeb: !isElectron,
isDesktop: isElectron,
};
}
+8 -1
View File
@@ -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:
+2 -1
View File
@@ -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",
})),
];
+2 -2
View File
@@ -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))