Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:sparkles: Support a shortcut for the tab switcher menu https://github.com/siyuan-note/siyuan/issues/19914

Daniel996004adaee1
diff --git a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100950-9op5xi1.sy b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100950-9op5xi1.sy
index 6e919add45..720ef4caa2 100644
--- a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100950-9op5xi1.sy
+++ b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100950-9op5xi1.sy
@@ -7,7 +7,7 @@
"id": "20200924100950-9op5xi1",
"title": "Shortcuts",
"type": "doc",
- "updated": "20260927164841"
+ "updated": "20260928085827"
},
"Children": [
{
@@ -51,6 +51,56 @@
}
]
},
+ {
+ "ID": "20260928085827-jxtln5i",
+ "Type": "NodeParagraph",
+ "Properties": {
+ "id": "20260928085827-jxtln5i",
+ "updated": "20260928085827"
+ },
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "On desktop, configure "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "Settings"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " - "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "Keymap"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " - "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "General"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " - "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "Switcher"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " to assign a shortcut to the tab switcher menu; no shortcut is assigned by default. The menu lists tabs in the active pane in tab bar order. Use the up/down arrow keys to select a tab, Enter to switch, and Esc to close the menu. This command is also available in the command panel."
+ }
+ ]
+ },
{
"ID": "20260925174006-1syj8e1",
"Type": "NodeParagraph",
diff --git a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200813004551-gm0pbn1.sy b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200813004551-gm0pbn1.sy
index db3da134ca..b51196269d 100644
--- a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200813004551-gm0pbn1.sy
+++ b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200813004551-gm0pbn1.sy
@@ -7,7 +7,7 @@
"id": "20200813004551-gm0pbn1",
"title": "快捷键",
"type": "doc",
- "updated": "20260927164841"
+ "updated": "20260928085827"
},
"Children": [
{
@@ -51,6 +51,56 @@
}
]
},
+ {
+ "ID": "20260928085827-161wwi2",
+ "Type": "NodeParagraph",
+ "Properties": {
+ "id": "20260928085827-161wwi2",
+ "updated": "20260928085827"
+ },
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "桌面端可在 "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "设置"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " - "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "快捷键"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " - "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "通用"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " - "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "页签切换"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " 中设置打开页签切换菜单的快捷键,默认未绑定按键。菜单按页签栏顺序列出当前活动分屏的页签,可使用上下方向键选择、回车键切换、Esc 关闭。也可从命令面板执行此命令。"
+ }
+ ]
+ },
{
"ID": "20260925174006-mz00jbc",
"Type": "NodeParagraph",
diff --git a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226122549-jktxego.sy b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226122549-jktxego.sy
index 78388614fd..7af03bcc00 100644
--- a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226122549-jktxego.sy
+++ b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226122549-jktxego.sy
@@ -7,7 +7,7 @@
"id": "20211226122549-jktxego",
"title": "快捷鍵",
"type": "doc",
- "updated": "20260927164841"
+ "updated": "20260928085827"
},
"Children": [
{
@@ -51,6 +51,56 @@
}
]
},
+ {
+ "ID": "20260928085827-6l4hbie",
+ "Type": "NodeParagraph",
+ "Properties": {
+ "id": "20260928085827-6l4hbie",
+ "updated": "20260928085827"
+ },
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "桌面端可在 "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "設定"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " - "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "快速鍵"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " - "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "通用"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " - "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "分頁切換"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " 中設定開啟頁籤切換選單的快捷鍵,預設未綁定按鍵。選單按頁籤列順序列出目前作用中分割視窗的頁籤,可使用上下方向鍵選擇、Enter 鍵切換、Esc 關閉。也可從命令面板執行此命令。"
+ }
+ ]
+ },
{
"ID": "20260925174006-m7i1hw9",
"Type": "NodeParagraph",
diff --git a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-xsbxokr.sy b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-xsbxokr.sy
index edc907c57e..f110811d06 100644
--- a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-xsbxokr.sy
+++ b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-xsbxokr.sy
@@ -9,7 +9,7 @@
"id": "20240530101000-xsbxokr",
"title": "ショートカット",
"type": "doc",
- "updated": "20260927164841"
+ "updated": "20260928085827"
},
"Children": [
{
@@ -49,6 +49,56 @@
}
]
},
+ {
+ "ID": "20260928085827-0dy3tdl",
+ "Type": "NodeParagraph",
+ "Properties": {
+ "id": "20260928085827-0dy3tdl",
+ "updated": "20260928085827"
+ },
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "デスクトップ版では "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "設定"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " - "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "ショートカット"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " - "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "一般"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " - "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "タブの切り替え"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " でタブ切り替えメニューのショートカットを設定できます。既定では割り当てられていません。メニューには、アクティブな分割ペインのタブがタブバーと同じ順序で表示されます。上下の矢印キーで選択し、Enter で切り替え、Esc で閉じます。コマンドパネルからも実行できます。"
+ }
+ ]
+ },
{
"ID": "20260925174006-lw5d4uc",
"Type": "NodeParagraph",
diff --git a/app/src/boot/globalEvent/command/global.ts b/app/src/boot/globalEvent/command/global.ts
index a6eaf3dd58..bca3fa8190 100644
--- a/app/src/boot/globalEvent/command/global.ts
+++ b/app/src/boot/globalEvent/command/global.ts
@@ -154,6 +154,9 @@ export const globalCommand = (command: string, app: App, range?: Range) => {
case "goToTabPrev":
switchTabByIndex(-2);
return true;
+ case "switchTab":
+ getActiveTab(false)?.parent.renderTabList(undefined, true);
+ return true;
case "mainMenu":
if (!isWindow()) {
workspaceMenu(app, document.querySelector("#barWorkspace").getBoundingClientRect());
diff --git a/app/src/boot/globalEvent/keydown.ts b/app/src/boot/globalEvent/keydown.ts
index c29fcf7f1c..6a2ae34a4d 100644
--- a/app/src/boot/globalEvent/keydown.ts
+++ b/app/src/boot/globalEvent/keydown.ts
@@ -1774,6 +1774,14 @@ export const windowKeyDown = (app: App, event: KeyboardEvent) => {
return;
}
+ if (matchHotKey(window.siyuan.config.keymap.general.switchTab, event)) {
+ if (!event.repeat) {
+ globalCommand("switchTab", app);
+ }
+ event.preventDefault();
+ return;
+ }
+
if (matchHotKey(window.siyuan.config.keymap.general.goToTab1, event) && !event.repeat) {
switchTabByIndex(0);
event.preventDefault();
diff --git a/app/src/command/nativeCatalog.test.ts b/app/src/command/nativeCatalog.test.ts
index 8c7ca97be8..754ffd3a7f 100644
--- a/app/src/command/nativeCatalog.test.ts
+++ b/app/src/command/nativeCatalog.test.ts
@@ -21,7 +21,7 @@ const expectedDesktopGeneralKeys = [
"splitLR", "splitMoveB", "splitMoveR", "splitTB", "switchLeftDock", "switchRightDock", "switchBottomDock",
"tabToWindow", "stickSearch", "toggleDock", "toggleLeftDockPanel", "toggleRightDockPanel",
"toggleBottomDockPanel", "unsplitAll", "unsplit", "recentClosed", "increaseEditorFontSize",
- "decreaseEditorFontSize", "resetEditorFontSize", "toggleWin",
+ "decreaseEditorFontSize", "resetEditorFontSize", "toggleWin", "switchTab",
];
const expectedMobileGeneralKeys = [
@@ -40,21 +40,25 @@ describe("native command catalog", () => {
assert.deepEqual([...DESKTOP_COMMAND_PANEL_GENERAL_KEYS], expectedDesktopGeneralKeys);
assert.deepEqual([...MOBILE_COMMAND_PANEL_GENERAL_KEYS], expectedMobileGeneralKeys);
assert.deepEqual([...COMMAND_PANEL_EDITOR_KEYS], ["switchReadonly", "switchAdjust"]);
- assert.equal(DESKTOP_COMMAND_PANEL_GENERAL_KEYS.length, 67);
+ assert.equal(DESKTOP_COMMAND_PANEL_GENERAL_KEYS.length, 68);
assert.equal(MOBILE_COMMAND_PANEL_GENERAL_KEYS.length, 26);
assert.equal(COMMAND_PANEL_EDITOR_KEYS.length, 2);
- assert.equal(NATIVE_COMMAND_CATALOG.length, 69);
+ assert.equal(NATIVE_COMMAND_CATALOG.length, 70);
assert.equal(new Set(NATIVE_COMMAND_CATALOG.map(item => item.id)).size, NATIVE_COMMAND_CATALOG.length);
});
it("filters all five frontends without exposing desktop-only commands", () => {
- assert.equal(getSupportedIds("desktop").length, 69);
- assert.equal(getSupportedIds("desktop-window").length, 69);
- assert.equal(getSupportedIds("browser-desktop").length, 68);
+ assert.equal(getSupportedIds("desktop").length, 70);
+ assert.equal(getSupportedIds("desktop-window").length, 70);
+ assert.equal(getSupportedIds("browser-desktop").length, 69);
assert.equal(getSupportedIds("mobile").length, 28);
assert.equal(getSupportedIds("browser-mobile").length, 28);
assert.equal(getSupportedIds("browser-desktop").includes("core.general.toggleWin"), false);
assert.equal(getSupportedIds("mobile").includes("core.general.graphView"), false);
+ assert.equal(getSupportedIds("desktop-window").includes("core.general.switchTab"), true);
+ assert.equal(getSupportedIds("browser-desktop").includes("core.general.switchTab"), true);
+ assert.equal(getSupportedIds("mobile").includes("core.general.switchTab"), false);
+ assert.equal(getSupportedIds("browser-mobile").includes("core.general.switchTab"), false);
});
it("maps legacy keys to stable IDs and keymap paths", () => {
diff --git a/app/src/command/nativeCatalog.ts b/app/src/command/nativeCatalog.ts
index 0998bf9e51..7e8f3f1327 100644
--- a/app/src/command/nativeCatalog.ts
+++ b/app/src/command/nativeCatalog.ts
@@ -8,7 +8,7 @@ export const DESKTOP_COMMAND_PANEL_GENERAL_KEYS = [
"splitLR", "splitMoveB", "splitMoveR", "splitTB", "switchLeftDock", "switchRightDock", "switchBottomDock",
"tabToWindow", "stickSearch", "toggleDock", "toggleLeftDockPanel", "toggleRightDockPanel",
"toggleBottomDockPanel", "unsplitAll", "unsplit", "recentClosed", "increaseEditorFontSize",
- "decreaseEditorFontSize", "resetEditorFontSize", "toggleWin",
+ "decreaseEditorFontSize", "resetEditorFontSize", "toggleWin", "switchTab",
] as const;
export const MOBILE_COMMAND_PANEL_GENERAL_KEYS = [
diff --git a/app/src/constants.ts b/app/src/constants.ts
index f77bdc905a..8508a7edc9 100644
--- a/app/src/constants.ts
+++ b/app/src/constants.ts
@@ -536,6 +536,7 @@ export abstract class Constants {
goToTab9: {default: "⌘9", custom: "⌘9"},
goToTabNext: {default: "⇧⌘]", custom: "⇧⌘]"},
goToTabPrev: {default: "⇧⌘[", custom: "⇧⌘["},
+ switchTab: {default: "", custom: ""},
goToEditTabNext: {default: "⌃⇥", custom: "⌃⇥"},
goToEditTabPrev: {default: "⌃⇧⇥", custom: "⌃⇧⇥"},
recentClosed: {default: "⇧⌘T", custom: "⇧⌘T"},
diff --git a/app/src/layout/Wnd.ts b/app/src/layout/Wnd.ts
index e2e5c087d7..224a490acd 100644
--- a/app/src/layout/Wnd.ts
+++ b/app/src/layout/Wnd.ts
@@ -861,7 +861,10 @@ export class Wnd {
event.stopPropagation();
}
- private renderTabList(target: HTMLElement) {
+ public renderTabList(target = this.headersElement.parentElement.querySelector<HTMLElement>('[data-type="more"]'), focus = false) {
+ if (!target || this.headersElement.children.length === 0) {
+ return;
+ }
if (!window.siyuan.menus.menu.element.classList.contains("fn__none") &&
window.siyuan.menus.menu.element.getAttribute("data-name") === Constants.MENU_TAB_LIST) {
window.siyuan.menus.menu.remove();
@@ -920,6 +923,22 @@ export class Wnd {
h: rect.height,
isLeft: true
});
+ if (focus) {
+ const menu = window.siyuan.menus.menu;
+ const activeElement = document.activeElement;
+ const currentElement = menu.element.querySelector<HTMLElement>(".b3-menu__item--selected") ||
+ menu.element.querySelector<HTMLElement>(".b3-menu__item");
+ currentElement?.classList.add("b3-menu__item--current");
+ currentElement?.focus({preventScroll: true});
+ currentElement?.scrollIntoView({block: "nearest"});
+ // 仅在焦点仍位于菜单内时恢复,避免页签切换后抢回原编辑器焦点。
+ menu.removeCB = () => {
+ if (activeElement instanceof HTMLElement && activeElement.isConnected &&
+ menu.element.contains(document.activeElement)) {
+ activeElement.focus({preventScroll: true});
+ }
+ };
+ }
}
private removeOverCounter(isSaveLayout = false) {
diff --git a/app/src/layout/tabList.test.ts b/app/src/layout/tabList.test.ts
new file mode 100644
index 0000000000..22c6f65f07
--- /dev/null
+++ b/app/src/layout/tabList.test.ts
@@ -0,0 +1,128 @@
+import {readFileSync} from "node:fs";
+import {join} from "node:path";
+import {runInNewContext} from "node:vm";
+import {describe, it} from "node:test";
+import * as assert from "node:assert/strict";
+import * as ts from "typescript";
+
+const source = ts.transpileModule(readFileSync(join(__dirname, "Wnd.ts"), "utf8"), {
+ compilerOptions: {module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020},
+}).outputText;
+
+const fixture = () => {
+ const document = {activeElement: undefined as any};
+ class Element {
+ classes = new Set<string>();
+ classList = {
+ add: (...names: string[]) => names.forEach(name => this.classes.add(name)),
+ contains: (name: string) => this.classes.has(name),
+ };
+ isConnected = true;
+ focus() { document.activeElement = this; }
+ scrollIntoView() { /* 模拟菜单项滚动,不依赖浏览器布局。 */ }
+ }
+ const original = new Element();
+ original.focus();
+ const items: Array<{element: Element, options: any, click?: (event: any) => void}> = [];
+ let menuName: string;
+ let popupCount = 0;
+ let switched: unknown;
+ const menuElement = Object.assign(new Element(), {
+ getAttribute: () => menuName,
+ setAttribute: (_name: string, value: string) => { menuName = value; },
+ contains: (element: unknown) => items.some(item => item.element === element),
+ querySelector: (selector: string) => items.find(item =>
+ selector === ".b3-menu__item" || item.options.current)?.element,
+ });
+ menuElement.classes.add("fn__none");
+ const menu = {
+ element: menuElement,
+ removeCB: undefined as (() => void) | undefined,
+ remove: () => {
+ menu.removeCB?.();
+ menu.removeCB = undefined;
+ items.length = 0;
+ menuName = undefined;
+ menuElement.classes.add("fn__none");
+ },
+ append: () => {},
+ popup: () => {
+ popupCount++;
+ menuElement.classes.delete("fn__none");
+ },
+ };
+ const header = (title: string, active: boolean) => ({
+ querySelector: (selector: string) => selector === ".item__text" ? {textContent: title} : null,
+ classList: {contains: () => active},
+ });
+ const headers = [header("first", false), header("second", true)];
+ const anchor = {getBoundingClientRect: () => ({left: 10, top: 20, width: 30, height: 40})};
+ const exports: any = {};
+ const dependencies: Record<string, object> = {
+ "../constants": {Constants: {MENU_TAB_LIST: "tab-list"}},
+ "../util/escape": {escapeHtml: (value: string) => value},
+ "../emoji/fileTreeIcon": {getFileTreeIconHTML: () => ""},
+ "../protyle/util/hasClosest": {hasClosestByClassName: () => false},
+ "../menus/Menu": {MenuItem: class {
+ element = new Element();
+ constructor(options: any) {
+ const item = {element: this.element, options, click: undefined as ((event: any) => void) | undefined};
+ items.push(item);
+ options.bind({addEventListener: (_type: string, callback: typeof item.click) => { item.click = callback; }});
+ }
+ }},
+ };
+ runInNewContext(source, {
+ exports, document, HTMLElement: Element,
+ window: {siyuan: {menus: {menu}}},
+ require: (name: string) => dependencies[name] || {},
+ });
+ const wnd = Object.create(exports.Wnd.prototype);
+ wnd.headersElement = {children: headers, parentElement: {querySelector: () => anchor}};
+ wnd.switchTab = (tab: unknown) => { switched = tab; new Element().focus(); };
+ wnd.showHeading = () => {};
+ return {wnd, menu, items, original, document, headers, anchor,
+ popupCount: () => popupCount, switched: () => switched};
+};
+
+describe("tab switcher keyboard entry", () => {
+ it("opens the current pane in header order and focuses its selected tab", () => {
+ const f = fixture();
+ f.wnd.renderTabList(undefined, true);
+ assert.deepEqual(f.items.map(item => item.options.label), ["first", "second"]);
+ assert.equal(f.document.activeElement, f.items[1].element);
+ assert.equal(f.items[1].element.classList.contains("b3-menu__item--current"), true);
+ f.menu.remove();
+ assert.equal(f.document.activeElement, f.original);
+ });
+
+ it("toggles an open menu without reopening it", () => {
+ const f = fixture();
+ f.wnd.renderTabList(undefined, true);
+ f.wnd.renderTabList(undefined, true);
+ assert.equal(f.popupCount(), 1);
+ assert.equal(f.menu.element.classList.contains("fn__none"), true);
+ assert.equal(f.document.activeElement, f.original);
+ });
+
+ it("does not restore the old editor after switching tabs", () => {
+ const f = fixture();
+ f.wnd.renderTabList(undefined, true);
+ f.items[0].click({target: {}, preventDefault: () => {}, stopPropagation: () => {}});
+ assert.equal(f.switched(), f.headers[0]);
+ assert.notEqual(f.document.activeElement, f.original);
+ });
+
+ it("preserves mouse focus and ignores empty panes or missing anchors", () => {
+ const f = fixture();
+ f.wnd.renderTabList(f.anchor);
+ assert.equal(f.document.activeElement, f.original);
+ f.menu.remove();
+ f.headers.length = 0;
+ f.wnd.renderTabList(undefined, true);
+ assert.equal(f.popupCount(), 1);
+ f.wnd.headersElement.parentElement.querySelector = (): null => null;
+ f.wnd.renderTabList(undefined, true);
+ assert.equal(f.popupCount(), 1);
+ });
+});
diff --git a/app/src/mobile/util/keydown.ts b/app/src/mobile/util/keydown.ts
index fe535a922c..bf9a4b6b15 100644
--- a/app/src/mobile/util/keydown.ts
+++ b/app/src/mobile/util/keydown.ts
@@ -15,6 +15,10 @@ export const mobileKeydown = (app: App, event: KeyboardEvent) => {
if (key === "openContextMenu") {
return false;
}
+ // 桌面页签菜单不拦截移动端的键盘输入。
+ if (key === "switchTab") {
+ return false;
+ }
if (matchHotKey(window.siyuan.config.keymap.general[key], event)) {
const protyle = getCurrentEditor()?.protyle;
if (protyle) {
diff --git a/app/src/mobile/util/tabShortcut.test.ts b/app/src/mobile/util/tabShortcut.test.ts
new file mode 100644
index 0000000000..f6aca434a4
--- /dev/null
+++ b/app/src/mobile/util/tabShortcut.test.ts
@@ -0,0 +1,28 @@
+import {readFileSync} from "node:fs";
+import {join} from "node:path";
+import {runInNewContext} from "node:vm";
+import {it} from "node:test";
+import * as assert from "node:assert/strict";
+import * as ts from "typescript";
+
+it("does not consume the desktop tab menu binding on mobile", () => {
+ const calls: string[] = [];
+ const exports: any = {};
+ const source = ts.transpileModule(readFileSync(join(__dirname, "keydown.ts"), "utf8"), {
+ compilerOptions: {module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020},
+ }).outputText;
+ const dependencies: Record<string, object> = {
+ "../../boot/globalEvent/commonHotkey": {filterHotkey: () => false},
+ "../../protyle/util/hotKey": {matchHotKey: () => true},
+ "../../command/executor": {execByCommand: () => calls.push("native")},
+ "../editor": {getCurrentEditor: () => ({protyle: {toolbar: {}}})},
+ "../../command/shortcutRuntime": {dispatchPluginShortcut: () => calls.push("plugin")},
+ };
+ runInNewContext(source, {
+ exports,
+ window: {siyuan: {config: {keymap: {general: {switchTab: {custom: "F8"}}}}}},
+ require: (name: string) => dependencies[name] || {},
+ });
+ exports.mobileKeydown({}, {key: "F8", preventDefault: () => calls.push("prevent")});
+ assert.deepEqual(calls, ["plugin"]);
+});
diff --git a/app/src/types/config.d.ts b/app/src/types/config.d.ts
index 3c80f65871..2fe196bc0f 100644
--- a/app/src/types/config.d.ts
+++ b/app/src/types/config.d.ts
@@ -1438,6 +1438,7 @@ declare namespace Config {
goToTab9?: IKey;
goToTabNext?: IKey;
goToTabPrev?: IKey;
+ switchTab?: IKey;
goToEditTabNext?: IKey;
goToEditTabPrev?: IKey;
recentClosed?: IKey;