feat(shortcuts): open data in a new tab

This commit is contained in:
二丫讲梵 authored and GitHub committed 2026-07-15 21:43:03 +08:00
1 parent 75652b10fe
commit 11536da7e5
16 files changed
+265 -23

No files matched your search

@@ -1,7 +1,27 @@
import { describe, expect, it } from "vitest";
import { eventToShortcut, matchesShortcut } from "@/lib/editor/keyboardShortcuts";
import { eventToModifierOnlyShortcut, eventToShortcut, matchesModifierOnlyShortcut, matchesShortcut } from "@/lib/editor/keyboardShortcuts";
describe("keyboard shortcut matching", () => {
it("records modifier-only mouse shortcut settings", () => {
expect(eventToModifierOnlyShortcut({ key: "Alt", altKey: true })).toBe("Alt");
expect(eventToModifierOnlyShortcut({ key: "Shift", shiftKey: true })).toBe("Shift");
expect(eventToModifierOnlyShortcut({ key: "Control", ctrlKey: true }, "Win32")).toBe("Mod");
expect(eventToModifierOnlyShortcut({ key: "Meta", metaKey: true }, "Win32")).toBe("Meta");
expect(eventToModifierOnlyShortcut({ key: "Meta", metaKey: true }, "MacIntel")).toBe("Mod");
expect(eventToModifierOnlyShortcut({ key: "Control", ctrlKey: true }, "MacIntel")).toBe("Ctrl");
expect(eventToModifierOnlyShortcut({ key: "A", altKey: true })).toBeNull();
});
it("matches a configured mouse modifier exactly", () => {
expect(matchesModifierOnlyShortcut({ altKey: true }, "Alt")).toBe(true);
expect(matchesModifierOnlyShortcut({ ctrlKey: true }, "Mod")).toBe(true);
expect(matchesModifierOnlyShortcut({ metaKey: true }, "Mod")).toBe(true);
expect(matchesModifierOnlyShortcut({ ctrlKey: true }, "Ctrl")).toBe(true);
expect(matchesModifierOnlyShortcut({ metaKey: true }, "Meta")).toBe(true);
expect(matchesModifierOnlyShortcut({ altKey: true, shiftKey: true }, "Alt")).toBe(false);
expect(matchesModifierOnlyShortcut({ shiftKey: true }, "")).toBe(false);
});
it("records the plus key without losing it to the separator", () => {
expect(eventToShortcut({ key: "+", ctrlKey: true })).toBe("Mod+Plus");
expect(eventToShortcut({ key: "+", ctrlKey: true, shiftKey: true })).toBe("Shift+Mod+Plus");
@@ -2,6 +2,11 @@ import { describe, expect, it } from "vitest";
import { formatShortcutDisplay, shortcutDisplayKeys } from "@/lib/editor/shortcutDisplay";
describe("shortcut display", () => {
it("shows the default mouse modifier as Option on macOS and Alt elsewhere", () => {
expect(formatShortcutDisplay("Alt", "MacIntel")).toBe("⌥");
expect(formatShortcutDisplay("Alt", "Win32")).toBe("Alt");
});
it("uses readable modifier labels on Windows", () => {
expect(shortcutDisplayKeys("Shift+Alt+U", "Win32")).toEqual(["Shift", "Alt", "U"]);
});
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { DEFAULT_SHORTCUT_SETTINGS, SHORTCUT_DEFINITIONS, findShortcutConflict, formatShortcut, normalizeShortcutSettings, shortcutToCodeMirrorKey, type ShortcutActionId } from "@/lib/editor/shortcutRegistry";
import { DEFAULT_SHORTCUT_SETTINGS, SHORTCUT_DEFINITIONS, findShortcutConflict, formatShortcut, normalizeModifierOnlyShortcut, normalizeShortcutSettings, shortcutToCodeMirrorKey, type ShortcutActionId } from "@/lib/editor/shortcutRegistry";
describe("shortcutRegistry editor actions", () => {
const formatterEditorActionIds: ShortcutActionId[] = [
@@ -22,6 +22,21 @@ describe("shortcutRegistry editor actions", () => {
];
const sidebarShortcutActionIds: ShortcutActionId[] = ["copySidebarSelection", "pasteSidebarSelection", "editSidebarConnection"];
it("registers the new-data-tab mouse modifier as a configurable sidebar shortcut", () => {
const definition = SHORTCUT_DEFINITIONS.find((item) => item.id === "openDataInNewTab");
expect(definition).toMatchObject({ scope: "sidebar", defaultShortcut: "Alt", inputKind: "modifier-only" });
expect(DEFAULT_SHORTCUT_SETTINGS.openDataInNewTab).toBe("Alt");
expect(formatShortcut(DEFAULT_SHORTCUT_SETTINGS.openDataInNewTab, "MacIntel")).toBe("Alt");
});
it("normalizes custom, cleared, and invalid modifier-only shortcuts", () => {
expect(normalizeShortcutSettings({ openDataInNewTab: "Shift" }).openDataInNewTab).toBe("Shift");
expect(normalizeShortcutSettings({ openDataInNewTab: "" }).openDataInNewTab).toBe("");
expect(normalizeShortcutSettings({ openDataInNewTab: "Mod+Enter" }).openDataInNewTab).toBe("Alt");
expect(normalizeModifierOnlyShortcut("Control")).toBe("Ctrl");
});
it("registers formatter editor shortcuts in the generic editor scope", () => {
for (const actionId of formatterEditorActionIds) {
const definition = SHORTCUT_DEFINITIONS.find((item) => item.id === actionId);