Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

feat(desktop): add numbered tab shortcuts (MUL-6923) (#7870)

ASDFGHoney01dbfae45cdd
diff --git a/apps/desktop/src/main/index.ts b/apps/desktop/src/main/index.ts
index 7a7fb3c8c4..0d19e3a4f1 100644
--- a/apps/desktop/src/main/index.ts
+++ b/apps/desktop/src/main/index.ts
@@ -53,6 +53,7 @@ import {
MAIN_RENDERER_CHANNEL_STATE_CHANNEL,
MainRendererMessageQueue,
parseMainRendererChannelState,
+ TAB_SELECTION_SHORTCUT_CHANNEL,
type MainRendererMessageChannel,
} from "../shared/main-renderer-messages";
import { AuthSessionCoordinator } from "./auth-session-coordinator";
@@ -268,6 +269,11 @@ function installWindowShortcutHandler(window: BrowserWindow): void {
// dedicated issue window — and from one that outlived the main window,
// which is recreated and only then handed the request.
dispatchToMainRenderer("settings:open", null);
+ } else if (typeof result === "object" && result.action === "select-tab") {
+ event.preventDefault();
+ // Product tabs only exist in the main window. Route there even when the
+ // chord came from a dedicated issue window, matching Settings behavior.
+ dispatchToMainRenderer(TAB_SELECTION_SHORTCUT_CHANNEL, result.key);
} else if (result) {
event.preventDefault();
}
diff --git a/apps/desktop/src/main/keyboard-shortcuts.test.ts b/apps/desktop/src/main/keyboard-shortcuts.test.ts
index 3768c82f86..a496b090d5 100644
--- a/apps/desktop/src/main/keyboard-shortcuts.test.ts
+++ b/apps/desktop/src/main/keyboard-shortcuts.test.ts
@@ -16,10 +16,16 @@ function makeWc(initialLevel = 0) {
function key(
k: string,
mods: Partial<Pick<ShortcutInput, "control" | "meta" | "alt" | "shift">> = {},
+ code = /^[0-9]$/.test(k)
+ ? `Digit${k}`
+ : /^[a-z]$/i.test(k)
+ ? `Key${k.toUpperCase()}`
+ : "",
): ShortcutInput {
return {
type: "keyDown",
key: k,
+ code,
control: false,
meta: false,
alt: false,
@@ -146,6 +152,149 @@ describe("handleAppShortcut — reset zoom", () => {
});
});
+describe("handleAppShortcut — direct tab selection (Cmd/Ctrl+1..9)", () => {
+ it.each([1, 2, 3, 4, 5, 6, 7, 8, 9] as const)(
+ "maps Cmd+%i on macOS",
+ (shortcutKey) => {
+ const wc = makeWc();
+ expect(
+ handleAppShortcut(
+ key(String(shortcutKey), { meta: true }),
+ wc,
+ "darwin",
+ ),
+ ).toEqual({ action: "select-tab", key: shortcutKey });
+ expect(wc.setZoomLevel).not.toHaveBeenCalled();
+ },
+ );
+
+ it.each(["linux", "win32"] as const)(
+ "maps Ctrl+1..9 on %s",
+ (platform) => {
+ const wc = makeWc();
+ for (let shortcutKey = 1; shortcutKey <= 9; shortcutKey += 1) {
+ expect(
+ handleAppShortcut(
+ key(String(shortcutKey), { control: true }),
+ wc,
+ platform,
+ ),
+ ).toEqual({ action: "select-tab", key: shortcutKey });
+ }
+ },
+ );
+
+ it("does not capture a missing primary modifier or the wrong platform modifier", () => {
+ const wc = makeWc();
+ expect(handleAppShortcut(key("1"), wc, "darwin")).toBe(false);
+ expect(
+ handleAppShortcut(key("1", { control: true }), wc, "darwin"),
+ ).toBe(false);
+ expect(
+ handleAppShortcut(key("1", { meta: true }), wc, "win32"),
+ ).toBe(false);
+ });
+
+ it("accepts layout-required Shift while rejecting secondary modifiers", () => {
+ const wc = makeWc();
+ expect(
+ handleAppShortcut(
+ key("1", { meta: true, shift: true }, "Digit1"),
+ wc,
+ "darwin",
+ ),
+ ).toEqual({ action: "select-tab", key: 1 });
+ expect(
+ handleAppShortcut(key("1", { meta: true, alt: true }), wc, "darwin"),
+ ).toBe(false);
+ expect(
+ handleAppShortcut(
+ key("1", { meta: true, control: true }),
+ wc,
+ "darwin",
+ ),
+ ).toBe(false);
+ });
+
+ it("does not consume logical punctuation from a physical number-row key", () => {
+ const wc = makeWc();
+ expect(
+ handleAppShortcut(
+ key("&", { control: true }, "Digit1"),
+ wc,
+ "win32",
+ ),
+ ).toBe(false);
+ expect(
+ handleAppShortcut(
+ key("ç", { control: true }, "Digit9"),
+ wc,
+ "win32",
+ ),
+ ).toBe(false);
+ expect(wc.setZoomLevel).not.toHaveBeenCalled();
+ });
+
+ it.each([1, 2, 3, 4, 5, 6, 7, 8, 9] as const)(
+ "maps Numpad%i when its logical key is numeric",
+ (shortcutKey) => {
+ const wc = makeWc();
+ expect(
+ handleAppShortcut(
+ key(
+ String(shortcutKey),
+ { control: true },
+ `Numpad${shortcutKey}`,
+ ),
+ wc,
+ "linux",
+ ),
+ ).toEqual({ action: "select-tab", key: shortcutKey });
+ },
+ );
+
+ it("does not consume a nonnumeric numpad key", () => {
+ const wc = makeWc();
+ expect(
+ handleAppShortcut(
+ key("End", { control: true }, "Numpad1"),
+ wc,
+ "win32",
+ ),
+ ).toBe(false);
+ });
+
+ it("uses a logical digit even when the physical key was remapped", () => {
+ const wc = makeWc();
+ expect(
+ handleAppShortcut(
+ key("1", { meta: true }, "KeyA"),
+ wc,
+ "darwin",
+ ),
+ ).toEqual({ action: "select-tab", key: 1 });
+ });
+
+ it("swallows auto-repeat without issuing another selection", () => {
+ const wc = makeWc();
+ expect(
+ handleAppShortcut(
+ { ...key("9", { meta: true }), isAutoRepeat: true },
+ wc,
+ "darwin",
+ ),
+ ).toBe(true);
+ });
+
+ it("keeps Cmd/Ctrl+0 assigned to zoom reset", () => {
+ const wc = makeWc(2);
+ expect(handleAppShortcut(key("0", { meta: true }), wc, "darwin")).toBe(
+ true,
+ );
+ expect(wc.currentLevel()).toBe(0);
+ });
+});
+
describe("handleAppShortcut — unrelated keys pass through", () => {
it("does not capture plain letters", () => {
const wc = makeWc();
diff --git a/apps/desktop/src/main/keyboard-shortcuts.ts b/apps/desktop/src/main/keyboard-shortcuts.ts
index 27026b0076..3145b3bf76 100644
--- a/apps/desktop/src/main/keyboard-shortcuts.ts
+++ b/apps/desktop/src/main/keyboard-shortcuts.ts
@@ -1,11 +1,13 @@
import type { WebContents } from "electron";
+import type { TabSelectionShortcutKey } from "../shared/main-renderer-messages";
-// Shape of the input subset we read from Electron's `before-input-event`.
-// Modeled as a structural type so the handler is unit-testable without a
-// real Electron Input instance.
+// Shape of the Electron `before-input-event` fields relevant to shortcut
+// policy. Modeled as a structural type so the handler is unit-testable
+// without a real Electron Input instance.
export type ShortcutInput = {
type: string;
key: string;
+ code: string;
control: boolean;
meta: boolean;
alt: boolean;
@@ -44,8 +46,14 @@ const ZOOM_MAX = 4.5;
* - `"close-tab"`: Cmd/Ctrl+W intercepted — caller should send IPC to renderer
* - `"open-settings"`: Cmd/Ctrl+, intercepted — caller should route the
* request to the tabbed main window
+ * - `{ action: "select-tab", key }`: Cmd/Ctrl+1..9 intercepted — caller
+ * should route the requested browser-style tab position to the main window
*/
-export type ShortcutResult = boolean | "close-tab" | "open-settings";
+export type ShortcutResult =
+ | boolean
+ | "close-tab"
+ | "open-settings"
+ | { action: "select-tab"; key: TabSelectionShortcutKey };
export function handleAppShortcut(
input: ShortcutInput,
@@ -65,6 +73,23 @@ export function handleAppShortcut(
if (!primary || !noSecondaryModifiers) return false;
+ // Browser-style direct tab selection. 1..8 address that exact position;
+ // 9 is interpreted by the renderer as "last tab" regardless of count.
+ // Main owns the chord so it works while focus is inside any editor/control
+ // and can prevent both renderer handlers and native accelerators from also
+ // acting. Match the logical key, as Settings records and persists shortcuts
+ // using KeyboardEvent.key. This keeps an AZERTY Ctrl+& override reachable;
+ // pressing Shift on that layout produces the logical key "1" and selects
+ // tab 1. On QWERTY, Shift+Digit1 produces "!", so that chord stays distinct.
+ // Holding the chord is swallowed without repeatedly changing MRU.
+ if (/^[1-9]$/.test(input.key)) {
+ if (input.isAutoRepeat) return true;
+ return {
+ action: "select-tab",
+ key: Number(input.key) as TabSelectionShortcutKey,
+ };
+ }
+
// Cmd/Ctrl + "=" (unshifted) or "+" (Shift+=) → zoom in.
if (
(input.key === "=" && !input.shift) ||
diff --git a/apps/desktop/src/preload/index.d.ts b/apps/desktop/src/preload/index.d.ts
index 9442364af0..e8f79ade7d 100644
--- a/apps/desktop/src/preload/index.d.ts
+++ b/apps/desktop/src/preload/index.d.ts
@@ -16,6 +16,7 @@ import type {
DaemonPrefs,
LocalRuntimeProbe,
} from "../shared/daemon-types";
+import type { TabSelectionShortcutKey } from "../shared/main-renderer-messages";
interface DesktopAPI {
/** App version + normalized OS, captured synchronously at preload time. */
@@ -108,6 +109,11 @@ interface DesktopAPI {
/** Listen for Cmd/Ctrl+, requests to open Settings, delivered to the main
* window whichever window had focus. Returns an unsubscribe function. */
onOpenSettings: (callback: () => void) => () => void;
+ /** Listen for Cmd/Ctrl+1..9 tab-selection requests, delivered to the main
+ * window whichever window had focus. Returns an unsubscribe function. */
+ onSelectTabShortcut: (
+ callback: (key: TabSelectionShortcutKey) => void,
+ ) => () => void;
/** Ask the main process to close the window. */
closeWindow: () => void;
/** Open an issue-detail tab in a dedicated native window. */
diff --git a/apps/desktop/src/preload/index.ts b/apps/desktop/src/preload/index.ts
index 179fd586b9..96ae1afa98 100644
--- a/apps/desktop/src/preload/index.ts
+++ b/apps/desktop/src/preload/index.ts
@@ -26,7 +26,10 @@ import type {
} from "../shared/daemon-types";
import {
MAIN_RENDERER_CHANNEL_STATE_CHANNEL,
+ parseTabSelectionShortcutKey,
+ TAB_SELECTION_SHORTCUT_CHANNEL,
type MainRendererMessageChannel,
+ type TabSelectionShortcutKey,
} from "../shared/main-renderer-messages";
// Synchronously fetch app metadata from main at preload time so the renderer
@@ -223,6 +226,18 @@ const desktopAPI = {
* an issue window, because Settings is a tab. Returns an unsubscribe fn. */
onOpenSettings: (callback: () => void) =>
subscribeToMainRendererChannel("settings:open", () => callback()),
+ /** Listen for fixed Cmd/Ctrl+1..9 tab-selection requests. Only the main
+ * window subscribes; main routes requests there from any focused window. */
+ onSelectTabShortcut: (
+ callback: (key: TabSelectionShortcutKey) => void,
+ ) =>
+ subscribeToMainRendererChannel<unknown>(
+ TAB_SELECTION_SHORTCUT_CHANNEL,
+ (payload) => {
+ const key = parseTabSelectionShortcutKey(payload);
+ if (key !== null) callback(key);
+ },
+ ),
/** Ask the main process to close the window (used after closing the last tab). */
closeWindow: () => ipcRenderer.send("window:close"),
/** Open a validated issue-detail route in a dedicated native window. */
diff --git a/apps/desktop/src/renderer/src/App.tsx b/apps/desktop/src/renderer/src/App.tsx
index 52c830546d..4505cabd76 100644
--- a/apps/desktop/src/renderer/src/App.tsx
+++ b/apps/desktop/src/renderer/src/App.tsx
@@ -20,6 +20,7 @@ import { IssueWindow } from "./components/issue-window";
import { useTabStore } from "./stores/tab-store";
import { useWindowOverlayStore } from "./stores/window-overlay-store";
import { useOpenSettingsShortcut } from "./hooks/use-open-settings-shortcut";
+import { useTabSelectionShortcut } from "./hooks/use-tab-selection-shortcut";
import { useDaemonIPCBridge } from "./platform/daemon-ipc-bridge";
import { syncDaemonOnLogin } from "./platform/daemon-login-sync";
import { createDesktopLocaleAdapter } from "./platform/i18n-adapter";
@@ -387,6 +388,9 @@ export default function App() {
// Mounted at the App root for the same reason as Cmd+W: the chord has to
// work in every renderer state, not only inside the tab shell.
useOpenSettingsShortcut();
+ // Fixed browser-style tab selection is also owned by main so it remains
+ // available while focus sits inside editors, inputs, menus, or dialogs.
+ useTabSelectionShortcut();
// Flush a freeze/crash breadcrumb the main process parked from a previous
// session. A true hang or process death can't report itself when it happens
diff --git a/apps/desktop/src/renderer/src/hooks/use-tab-selection-shortcut.test.tsx b/apps/desktop/src/renderer/src/hooks/use-tab-selection-shortcut.test.tsx
new file mode 100644
index 0000000000..9982d6cdb9
--- /dev/null
+++ b/apps/desktop/src/renderer/src/hooks/use-tab-selection-shortcut.test.tsx
@@ -0,0 +1,160 @@
+// @vitest-environment jsdom
+import { beforeEach, describe, expect, it, vi } from "vitest";
+import { render } from "@testing-library/react";
+import type { TabSelectionShortcutKey } from "../../../shared/main-renderer-messages";
+import { useTabStore, type TabSession } from "@/stores/tab-store";
+import { useWindowOverlayStore } from "@/stores/window-overlay-store";
+import {
+ selectTabByShortcut,
+ useTabSelectionShortcut,
+} from "./use-tab-selection-shortcut";
+
+function Probe() {
+ useTabSelectionShortcut();
+ return null;
+}
+
+function makeTab(index: number): TabSession {
+ const url = `/acme/issues/${index}`;
+ return {
+ id: `t${index}`,
+ url,
+ resourceKey: url,
+ title: `Tab ${index}`,
+ pinned: index === 1,
+ history: { stack: [url, `${url}?view=detail`], index: 1 },
+ memento: {
+ scroll: { [`${url}::main`]: { top: index * 10, height: 1000 } },
+ view: { [`${url}::selection`]: `item-${index}` },
+ },
+ };
+}
+
+function seedTabs(count: number, activeIndex = 1): void {
+ const tabs = Array.from({ length: count }, (_, index) => makeTab(index + 1));
+ useTabStore.setState({
+ activeWorkspaceSlug: "acme",
+ byWorkspace: {
+ acme: {
+ tabs,
+ activeTabId: `t${activeIndex}`,
+ recentTabIds: [],
+ },
+ },
+ });
+}
+
+function activeTabId(): string | undefined {
+ return useTabStore.getState().byWorkspace.acme?.activeTabId;
+}
+
+function stubDesktopAPI(kind: "main" | "issue") {
+ let handler: ((key: TabSelectionShortcutKey) => void) | null = null;
+ const unsubscribe = vi.fn();
+ const onSelectTabShortcut = vi.fn(
+ (callback: (key: TabSelectionShortcutKey) => void) => {
+ handler = callback;
+ return unsubscribe;
+ },
+ );
+ (window as unknown as { desktopAPI: Record<string, unknown> }).desktopAPI = {
+ windowContext:
+ kind === "main"
+ ? { kind: "main" }
+ : { kind: "issue", path: "/acme/issues/abc", workspaceSlug: "acme" },
+ onSelectTabShortcut,
+ };
+ return {
+ onSelectTabShortcut,
+ unsubscribe,
+ deliver: (key: TabSelectionShortcutKey) => handler?.(key),
+ };
+}
+
+describe("selectTabByShortcut", () => {
+ beforeEach(() => {
+ seedTabs(10);
+ useWindowOverlayStore.setState({ overlay: null });
+ });
+
+ it.each([1, 2, 3, 4, 5, 6, 7, 8] as const)(
+ "selects exact tab position %i",
+ (key) => {
+ selectTabByShortcut(key);
+ expect(activeTabId()).toBe(`t${key}`);
+ },
+ );
+
+ it.each([1, 3, 10])(
+ "selects the last of %i tabs for shortcut 9",
+ (tabCount) => {
+ seedTabs(tabCount);
+ selectTabByShortcut(9);
+ expect(activeTabId()).toBe(`t${tabCount}`);
+ },
+ );
+
+ it("does nothing when the requested exact position does not exist", () => {
+ seedTabs(3, 2);
+ selectTabByShortcut(8);
+ expect(activeTabId()).toBe("t2");
+ });
+
+ it("preserves every tab session while changing selection", () => {
+ const before = useTabStore.getState().byWorkspace.acme.tabs;
+
+ selectTabByShortcut(7);
+
+ const group = useTabStore.getState().byWorkspace.acme;
+ expect(group.activeTabId).toBe("t7");
+ expect(group.tabs).toBe(before);
+ expect(group.tabs).toEqual(before);
+ });
+
+ it("does nothing without a visible tab group", () => {
+ useTabStore.setState({ activeWorkspaceSlug: null });
+ expect(() => selectTabByShortcut(1)).not.toThrow();
+
+ useTabStore.setState({ activeWorkspaceSlug: "missing" });
+ expect(() => selectTabByShortcut(9)).not.toThrow();
+ });
+
+ it("does not switch a hidden tab while a window overlay is active", () => {
+ useWindowOverlayStore.setState({ overlay: { type: "onboarding" } });
+ selectTabByShortcut(5);
+ expect(activeTabId()).toBe("t1");
+ });
+});
+
+describe("useTabSelectionShortcut", () => {
+ beforeEach(() => {
+ seedTabs(10);
+ useWindowOverlayStore.setState({ overlay: null });
+ });
+
+ it("selects a tab when main delivers the fixed shortcut", () => {
+ const { deliver } = stubDesktopAPI("main");
+ render(<Probe />);
+
+ deliver(4);
+
+ expect(activeTabId()).toBe("t4");
+ });
+
+ it("unsubscribes when the main renderer unmounts", () => {
+ const { unsubscribe } = stubDesktopAPI("main");
+ const view = render(<Probe />);
+
+ view.unmount();
+
+ expect(unsubscribe).toHaveBeenCalledOnce();
+ });
+
+ it("does not subscribe in a dedicated issue window", () => {
+ const { onSelectTabShortcut } = stubDesktopAPI("issue");
+
+ render(<Probe />);
+
+ expect(onSelectTabShortcut).not.toHaveBeenCalled();
+ });
+});
diff --git a/apps/desktop/src/renderer/src/hooks/use-tab-selection-shortcut.ts b/apps/desktop/src/renderer/src/hooks/use-tab-selection-shortcut.ts
new file mode 100644
index 0000000000..8e4ff8ed17
--- /dev/null
+++ b/apps/desktop/src/renderer/src/hooks/use-tab-selection-shortcut.ts
@@ -0,0 +1,44 @@
+import { useEffect } from "react";
+import type { TabSelectionShortcutKey } from "../../../shared/main-renderer-messages";
+import { useTabStore } from "@/stores/tab-store";
+import { useWindowOverlayStore } from "@/stores/window-overlay-store";
+
+/**
+ * Select a product tab using browser numbering semantics:
+ *
+ * - 1..8 select that exact one-based position.
+ * - 9 always selects the final tab, even when more than nine tabs exist.
+ *
+ * Missing positions deliberately no-op. Activation goes through the tab store
+ * so the coordinator updates the visible route while every session keeps its
+ * own history and memento.
+ */
+export function selectTabByShortcut(key: TabSelectionShortcutKey): void {
+ if (useWindowOverlayStore.getState().overlay) return;
+
+ const store = useTabStore.getState();
+ const slug = store.activeWorkspaceSlug;
+ if (!slug) return;
+
+ const group = store.byWorkspace[slug];
+ if (!group) return;
+
+ const tab = key === 9 ? group.tabs.at(-1) : group.tabs[key - 1];
+ if (!tab) return;
+
+ store.setActiveTab(tab.id);
+}
+
+/**
+ * Receive fixed Cmd/Ctrl+1..9 accelerators from Electron's main process.
+ * Only the tabbed main window subscribes because main routes the shortcut
+ * there regardless of which window or renderer control currently has focus.
+ */
+export function useTabSelectionShortcut(): void {
+ useEffect(() => {
+ if (window.desktopAPI.windowContext?.kind === "issue") return undefined;
+ // Optional call keeps renderer HMR safe while an old preload remains
+ // attached to a refreshed React tree.
+ return window.desktopAPI.onSelectTabShortcut?.(selectTabByShortcut);
+ }, []);
+}
diff --git a/apps/desktop/src/shared/main-renderer-messages.test.ts b/apps/desktop/src/shared/main-renderer-messages.test.ts
index b3a44a52c2..07093e017c 100644
--- a/apps/desktop/src/shared/main-renderer-messages.test.ts
+++ b/apps/desktop/src/shared/main-renderer-messages.test.ts
@@ -3,6 +3,8 @@ import { describe, expect, it, vi } from "vitest";
import {
MainRendererMessageQueue,
parseMainRendererChannelState,
+ parseTabSelectionShortcutKey,
+ TAB_SELECTION_SHORTCUT_CHANNEL,
} from "./main-renderer-messages";
describe("MainRendererMessageQueue", () => {
@@ -64,5 +66,24 @@ describe("parseMainRendererChannelState", () => {
expect(
parseMainRendererChannelState({ channel: "auth:token", ready: "yes" }),
).toBeNull();
+ expect(
+ parseMainRendererChannelState({
+ channel: TAB_SELECTION_SHORTCUT_CHANNEL,
+ ready: true,
+ }),
+ ).toEqual({ channel: TAB_SELECTION_SHORTCUT_CHANNEL, ready: true });
});
});
+
+describe("parseTabSelectionShortcutKey", () => {
+ it.each([1, 2, 3, 4, 5, 6, 7, 8, 9])("accepts shortcut key %i", (key) => {
+ expect(parseTabSelectionShortcutKey(key)).toBe(key);
+ });
+
+ it.each([0, 10, 1.5, "1", null, undefined])(
+ "rejects invalid shortcut payload %j",
+ (value) => {
+ expect(parseTabSelectionShortcutKey(value)).toBeNull();
+ },
+ );
+});
diff --git a/apps/desktop/src/shared/main-renderer-messages.ts b/apps/desktop/src/shared/main-renderer-messages.ts
index cb1a0c868c..c02e1e05d1 100644
--- a/apps/desktop/src/shared/main-renderer-messages.ts
+++ b/apps/desktop/src/shared/main-renderer-messages.ts
@@ -6,11 +6,28 @@
export const MAIN_RENDERER_CHANNEL_STATE_CHANNEL =
"main-renderer:channel-state";
+export const TAB_SELECTION_SHORTCUT_CHANNEL = "tab:select-by-shortcut";
+
+export const TAB_SELECTION_SHORTCUT_KEYS = [1, 2, 3, 4, 5, 6, 7, 8, 9] as const;
+
+export type TabSelectionShortcutKey =
+ (typeof TAB_SELECTION_SHORTCUT_KEYS)[number];
+
+export function parseTabSelectionShortcutKey(
+ value: unknown,
+): TabSelectionShortcutKey | null {
+ return typeof value === "number" &&
+ TAB_SELECTION_SHORTCUT_KEYS.includes(value as TabSelectionShortcutKey)
+ ? (value as TabSelectionShortcutKey)
+ : null;
+}
+
export const MAIN_RENDERER_MESSAGE_CHANNELS = [
"auth:token",
"invite:open",
"inbox:open",
"settings:open",
+ TAB_SELECTION_SHORTCUT_CHANNEL,
] as const;
export type MainRendererMessageChannel =
diff --git a/packages/core/shortcuts/definitions.test.ts b/packages/core/shortcuts/definitions.test.ts
index 360152a0a5..3147381308 100644
--- a/packages/core/shortcuts/definitions.test.ts
+++ b/packages/core/shortcuts/definitions.test.ts
@@ -21,7 +21,12 @@ import {
function keyEvent(
key: string,
- modifiers: Partial<Pick<KeyboardEvent, "metaKey" | "ctrlKey" | "altKey" | "shiftKey">> = {},
+ fields: Partial<
+ Pick<
+ KeyboardEvent,
+ "code" | "metaKey" | "ctrlKey" | "altKey" | "shiftKey"
+ >
+ > = {},
): KeyboardEvent {
return {
key,
@@ -29,7 +34,7 @@ function keyEvent(
ctrlKey: false,
altKey: false,
shiftKey: false,
- ...modifiers,
+ ...fields,
} as KeyboardEvent;
}
@@ -195,6 +200,47 @@ describe("keyboard shortcut definitions", () => {
expect(isReservedShortcut(createShortcutChord(","), "macos", "desktop")).toBe(false);
});
+ it("reserves browser-style tab selection on every platform and runtime", () => {
+ for (const key of ["1", "2", "3", "4", "5", "6", "7", "8", "9"]) {
+ const chord = createShortcutChord(key, { primary: true });
+ for (const platform of ["macos", "windows", "linux"] as const) {
+ for (const runtime of ["web", "desktop"] as const) {
+ expect(isReservedShortcut(chord, platform, runtime)).toBe(true);
+ expect(
+ isShortcutAllowedForAction("openSearch", chord, platform, runtime),
+ ).toBe(false);
+ }
+ }
+ }
+ expect(
+ isReservedShortcut(createShortcutChord("1"), "macos", "desktop"),
+ ).toBe(false);
+ });
+
+ it("models layout-sensitive number-row chords by their logical key", () => {
+ const ampersand = shortcutFromEvent(
+ keyEvent("&", { code: "Digit1", ctrlKey: true }),
+ "windows",
+ );
+ expect(ampersand).toEqual(
+ createShortcutChord("&", { primary: true }),
+ );
+ expect(isReservedShortcut(ampersand!, "windows", "desktop")).toBe(
+ false,
+ );
+
+ const shiftedDigit = shortcutFromEvent(
+ keyEvent("1", { code: "Digit1", ctrlKey: true, shiftKey: true }),
+ "windows",
+ );
+ expect(shiftedDigit).toEqual(
+ createShortcutChord("1", { primary: true, shift: true }),
+ );
+ expect(isReservedShortcut(shiftedDigit!, "windows", "desktop")).toBe(
+ true,
+ );
+ });
+
it("reserves browser-owned accelerators on web but frees the bare chords on desktop", () => {
for (const key of ["P", "L", "T", "N", "D", "U"]) {
const chord = createShortcutChord(key, { primary: true });
diff --git a/packages/core/shortcuts/definitions.ts b/packages/core/shortcuts/definitions.ts
index da6ebcd418..b6052fcdbf 100644
--- a/packages/core/shortcuts/definitions.ts
+++ b/packages/core/shortcuts/definitions.ts
@@ -313,6 +313,11 @@ const PRIMARY_RESERVED_KEYS = new Set([
"A", "C", "V", "X", "Y", "Z",
// Zoom accelerators: fixed app shortcuts on desktop, browser zoom on web.
"Equals", "Plus", "Minus", "Underscore", "0",
+ // Browser-style direct tab selection: browsers own these on web and the
+ // desktop main process owns them for product tabs. Keeping them reserved
+ // also sanitizes any conflicting shortcut override persisted by an older
+ // app version.
+ "1", "2", "3", "4", "5", "6", "7", "8", "9",
]);
// Accelerators owned by the browser UI around a tab: print, address bar,
diff --git a/packages/core/shortcuts/store.test.ts b/packages/core/shortcuts/store.test.ts
index d6f21d6030..f72b8a16b0 100644
--- a/packages/core/shortcuts/store.test.ts
+++ b/packages/core/shortcuts/store.test.ts
@@ -85,6 +85,15 @@ describe("shortcut store", () => {
expect(sanitizeShortcutOverrides({ openSearch: cmdP })).toEqual({});
});
+ it("keeps persisted punctuation overrides that remain reachable on desktop", () => {
+ const ctrlAmpersand = createShortcutChord("&", { primary: true });
+
+ configureShortcutRuntime("desktop");
+ expect(
+ sanitizeShortcutOverrides({ openSearch: ctrlAmpersand }),
+ ).toEqual({ openSearch: ctrlAmpersand });
+ });
+
it("finds conflicts against defaults and overrides", () => {
expect(
findShortcutConflict(
@@ -93,7 +102,7 @@ describe("shortcut store", () => {
),
).toBe("openSearch");
- const custom = createShortcutChord("1", { primary: true });
+ const custom = createShortcutChord("G", { primary: true });
useShortcutStore.getState().setShortcut("goInbox", custom);
expect(findShortcutConflict("goChat", custom)).toBe("goInbox");
});
diff --git a/packages/views/locales/en/settings.json b/packages/views/locales/en/settings.json
index 2f8a3aaca6..1c385a0ccb 100644
--- a/packages/views/locales/en/settings.json
+++ b/packages/views/locales/en/settings.json
@@ -257,6 +257,8 @@
"description": "Window and accessibility shortcuts stay fixed so they remain reliable. Zoom and tab controls apply to the desktop app.",
"open_settings": "Open Settings",
"close_tab": "Close active tab",
+ "select_tab_1_to_8": "Select tab 1–8",
+ "select_last_tab": "Select last tab",
"zoom_in": "Zoom in",
"zoom_out": "Zoom out",
"reset_zoom": "Reset zoom",
diff --git a/packages/views/locales/ja/settings.json b/packages/views/locales/ja/settings.json
index 3dfcdc95ab..8a9c956a97 100644
--- a/packages/views/locales/ja/settings.json
+++ b/packages/views/locales/ja/settings.json
@@ -257,6 +257,8 @@
"description": "ウィンドウとアクセシビリティのショートカットは信頼性のため固定されています。ズームとタブ操作はデスクトップアプリに適用されます。",
"open_settings": "設定を開く",
"close_tab": "アクティブなタブを閉じる",
+ "select_tab_1_to_8": "1〜8番目のタブを選択",
+ "select_last_tab": "最後のタブを選択",
"zoom_in": "拡大",
"zoom_out": "縮小",
"reset_zoom": "ズームをリセット",
diff --git a/packages/views/locales/ko/settings.json b/packages/views/locales/ko/settings.json
index 32d486f11a..fce0a77a2e 100644
--- a/packages/views/locales/ko/settings.json
+++ b/packages/views/locales/ko/settings.json
@@ -257,6 +257,8 @@
"description": "창 및 접근성 단축키는 안정성을 위해 고정됩니다. 확대/축소 및 탭 제어는 데스크톱 앱에 적용됩니다.",
"open_settings": "설정 열기",
"close_tab": "활성 탭 닫기",
+ "select_tab_1_to_8": "1~8번째 탭 선택",
+ "select_last_tab": "마지막 탭 선택",
"zoom_in": "확대",
"zoom_out": "축소",
"reset_zoom": "확대/축소 재설정",
diff --git a/packages/views/locales/zh-Hans/settings.json b/packages/views/locales/zh-Hans/settings.json
index 29faa20ec0..3f0e9d39f8 100644
--- a/packages/views/locales/zh-Hans/settings.json
+++ b/packages/views/locales/zh-Hans/settings.json
@@ -257,6 +257,8 @@
"description": "窗口和无障碍快捷键保持固定,确保始终可靠。缩放和标签页操作仅适用于桌面端。",
"open_settings": "打开设置",
"close_tab": "关闭当前标签页",
+ "select_tab_1_to_8": "选择第 1–8 个标签页",
+ "select_last_tab": "选择最后一个标签页",
"zoom_in": "放大",
"zoom_out": "缩小",
"reset_zoom": "重置缩放",
diff --git a/packages/views/settings/components/keyboard-shortcuts-tab.test.tsx b/packages/views/settings/components/keyboard-shortcuts-tab.test.tsx
index 3a043283e6..5db971db57 100644
--- a/packages/views/settings/components/keyboard-shortcuts-tab.test.tsx
+++ b/packages/views/settings/components/keyboard-shortcuts-tab.test.tsx
@@ -3,6 +3,7 @@ import { cleanup, fireEvent, screen, within } from "@testing-library/react";
import {
createShortcutChord,
configureShortcutPlatform,
+ configureShortcutRuntime,
getShortcut,
useShortcutStore,
} from "@multica/core/shortcuts";
@@ -18,6 +19,7 @@ describe("KeyboardShortcutsTab", () => {
afterEach(() => {
cleanup();
configureShortcutPlatform(null);
+ configureShortcutRuntime(null);
useShortcutStore.getState().resetAll();
});
@@ -38,6 +40,17 @@ describe("KeyboardShortcutsTab", () => {
expect(within(rightSidebarRecorder).getByTitle("/")).toHaveTextContent("/");
});
+ it("shows the fixed numbered tab shortcuts", () => {
+ renderWithI18n(<KeyboardShortcutsTab />);
+
+ expect(screen.getByText("Select tab 1–8")).toBeInTheDocument();
+ expect(screen.getByText("Select last tab")).toBeInTheDocument();
+ expect(
+ screen.getByRole("img", { name: "Ctrl+1–8" }),
+ ).toBeInTheDocument();
+ expect(screen.getByRole("img", { name: "Ctrl+9" })).toBeInTheDocument();
+ });
+
it("records a shortcut and applies it immediately", () => {
renderWithI18n(<KeyboardShortcutsTab />);
const recorder = screen.getByRole("button", {
@@ -54,6 +67,26 @@ describe("KeyboardShortcutsTab", () => {
expect(within(recorder).getByTitle("E")).toHaveTextContent("E");
});
+ it("records logical punctuation from a physical number-row key", () => {
+ configureShortcutRuntime("desktop");
+ renderWithI18n(<KeyboardShortcutsTab />);
+ const recorder = screen.getByRole("button", {
+ name: "Change shortcut for Open search",
+ });
+
+ fireEvent.click(recorder);
+ fireEvent.keyDown(recorder, {
+ key: "&",
+ code: "Digit1",
+ ctrlKey: true,
+ });
+
+ expect(getShortcut("openSearch")).toEqual(
+ createShortcutChord("&", { primary: true }),
+ );
+ expect(screen.queryByRole("alert")).not.toBeInTheDocument();
+ });
+
it("only captures keys while the recorder is active", () => {
renderWithI18n(<KeyboardShortcutsTab />);
const recorder = screen.getByRole("button", {
diff --git a/packages/views/settings/components/keyboard-shortcuts-tab.tsx b/packages/views/settings/components/keyboard-shortcuts-tab.tsx
index da5b6d428c..50cd017d38 100644
--- a/packages/views/settings/components/keyboard-shortcuts-tab.tsx
+++ b/packages/views/settings/components/keyboard-shortcuts-tab.tsx
@@ -197,6 +197,8 @@ export function KeyboardShortcutsTab() {
<SettingsCard>
<FixedShortcutRow label={t(($) => $.shortcuts.fixed.open_settings)} shortcut={createShortcutChord(",", { primary: true })} />
<FixedShortcutRow label={t(($) => $.shortcuts.fixed.close_tab)} shortcut={createShortcutChord("W", { primary: true })} />
+ <FixedShortcutRow label={t(($) => $.shortcuts.fixed.select_tab_1_to_8)} shortcut={createShortcutChord("1–8", { primary: true })} />
+ <FixedShortcutRow label={t(($) => $.shortcuts.fixed.select_last_tab)} shortcut={createShortcutChord("9", { primary: true })} />
<FixedShortcutRow label={t(($) => $.shortcuts.fixed.zoom_in)} shortcut={createShortcutChord("Plus", { primary: true })} />
<FixedShortcutRow label={t(($) => $.shortcuts.fixed.zoom_out)} shortcut={createShortcutChord("Minus", { primary: true })} />
<FixedShortcutRow label={t(($) => $.shortcuts.fixed.reset_zoom)} shortcut={createShortcutChord("0", { primary: true })} />