feat(shortcuts): add close other tabs shortcut

This commit is contained in:
vrustx authored and GitHub committed 2026-07-20 23:31:26 +08:00
1 parent e143a76e1f
commit d2975fc015
7 files changed
+127 -5

No files matched your search

@@ -19,6 +19,11 @@ describe("shortcut display", () => {
expect(shortcutDisplayKeys("Mod+Alt+Enter", "MacIntel")).toEqual(["⌘", "⌥", "↵"]);
});
it("formats the close other tabs shortcut by platform", () => {
expect(formatShortcutDisplay("Alt+Mod+W", "MacIntel")).toBe("⌥ ⌘ W");
expect(formatShortcutDisplay("Shift+Alt+W", "Win32")).toBe("Shift + Alt + W");
});
it("formats shortcut pills with platform separators", () => {
expect(formatShortcutDisplay("Shift+Alt+ArrowUp", "Win32")).toBe("Shift + Alt + ↑");
expect(formatShortcutDisplay("Shift+Alt+ArrowUp", "MacIntel")).toBe("⇧ ⌥ ↑");
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { DEFAULT_SHORTCUT_SETTINGS, SHORTCUT_DEFINITIONS, findShortcutConflict, formatShortcut, normalizeModifierOnlyShortcut, normalizeShortcutSettings, shortcutToCodeMirrorKey, type ShortcutActionId } from "@/lib/editor/shortcutRegistry";
import { closeOtherTabsDefaultShortcut, DEFAULT_SHORTCUT_SETTINGS, SHORTCUT_DEFINITIONS, findShortcutConflict, formatShortcut, normalizeModifierOnlyShortcut, normalizeShortcutSettings, shortcutToCodeMirrorKey, type ShortcutActionId } from "@/lib/editor/shortcutRegistry";
describe("shortcutRegistry editor actions", () => {
const formatterEditorActionIds: ShortcutActionId[] = [
@@ -30,6 +30,20 @@ describe("shortcutRegistry editor actions", () => {
expect(formatShortcut(DEFAULT_SHORTCUT_SETTINGS.openDataInNewTab, "MacIntel")).toBe("Alt");
});
it("resolves the close-other-tabs default per platform and heals cross-platform synced defaults", () => {
// 本测试环境(darwin):默认应为 macOS 组合
expect(DEFAULT_SHORTCUT_SETTINGS.closeOtherTabs).toBe(closeOtherTabsDefaultShortcut());
expect(closeOtherTabsDefaultShortcut("MacIntel")).toBe("Alt+Mod+W");
// Windows/Linux 不含 Ctrl+Alt(AltGr)也不含 Ctrl+Shift+W(浏览器关窗保留键)
expect(closeOtherTabsDefaultShortcut("Win32")).toBe("Shift+Alt+W");
expect(closeOtherTabsDefaultShortcut("Linux x86_64")).toBe("Shift+Alt+W");
// 云同步把另一平台的默认值带过来:视为未自定义,按本机平台还原
expect(normalizeShortcutSettings({ closeOtherTabs: "Alt+Mod+W" }).closeOtherTabs).toBe(closeOtherTabsDefaultShortcut());
expect(normalizeShortcutSettings({ closeOtherTabs: "Shift+Alt+W" }).closeOtherTabs).toBe(closeOtherTabsDefaultShortcut());
// 用户真正自定义的组合原样保留
expect(normalizeShortcutSettings({ closeOtherTabs: "Shift+Mod+O" }).closeOtherTabs).toBe("Shift+Mod+O");
});
it("normalizes custom, cleared, and invalid modifier-only shortcuts", () => {
expect(normalizeShortcutSettings({ openDataInNewTab: "Shift" }).openDataInNewTab).toBe("Shift");
expect(normalizeShortcutSettings({ openDataInNewTab: "" }).openDataInNewTab).toBe("");