1 parent
cd18b7a3db
commit
f621e40655
15 files changed
+457
-2
No files matched your search
@@ -1,5 +1,17 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { eventToModifierOnlyShortcut, eventToShortcut, isExecuteSqlInNewResultTabShortcut, isGoToColumnShortcut, matchesModifierOnlyShortcut, matchesShortcut, tabSwitcherDirectionFromShortcut } from "@/lib/editor/keyboardShortcuts";
|
||||
import {
|
||||
eventToModifierOnlyShortcut,
|
||||
eventToShortcut,
|
||||
isExecuteSqlInNewResultTabShortcut,
|
||||
isGoToColumnShortcut,
|
||||
isGoToFirstPageShortcut,
|
||||
isGoToLastPageShortcut,
|
||||
isGoToNextPageShortcut,
|
||||
isGoToPreviousPageShortcut,
|
||||
matchesModifierOnlyShortcut,
|
||||
matchesShortcut,
|
||||
tabSwitcherDirectionFromShortcut,
|
||||
} from "@/lib/editor/keyboardShortcuts";
|
||||
import { formatShortcutDisplay, isMacShortcutPlatform } from "@/lib/editor/shortcutDisplay";
|
||||
|
||||
describe("keyboard shortcut matching", () => {
|
||||
@@ -94,6 +106,21 @@ describe("keyboard shortcut matching", () => {
|
||||
expect(isGoToColumnShortcut({ key: "g", ctrlKey: true }, { goToColumn: "" })).toBe(false);
|
||||
expect(isGoToColumnShortcut({ key: "g", ctrlKey: true, isComposing: true }, { goToColumn: "Mod+G" })).toBe(false);
|
||||
});
|
||||
|
||||
it.each([
|
||||
["goToFirstPage", isGoToFirstPageShortcut, "F1"],
|
||||
["goToPreviousPage", isGoToPreviousPageShortcut, "F2"],
|
||||
["goToNextPage", isGoToNextPageShortcut, "F3"],
|
||||
["goToLastPage", isGoToLastPageShortcut, "F4"],
|
||||
] as const)("matches only the configured pagination shortcut for %s", (actionId, matcher, key) => {
|
||||
const shortcuts = { [actionId]: `Alt+${key}` };
|
||||
|
||||
expect(matcher({ key, altKey: true }, shortcuts)).toBe(true);
|
||||
expect(matcher({ key }, shortcuts)).toBe(false);
|
||||
expect(matcher({ key: "F8", altKey: true }, shortcuts)).toBe(false);
|
||||
expect(matcher({ key, altKey: true, isComposing: true }, shortcuts)).toBe(false);
|
||||
expect(matcher({ key, altKey: true })).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("tabSwitcherDirectionFromShortcut", () => {
|
||||
|
||||
@@ -25,6 +25,43 @@ describe("shortcutRegistry editor actions", () => {
|
||||
];
|
||||
const sidebarShortcutActionIds: ShortcutActionId[] = ["copySidebarSelection", "pasteSidebarSelection", "editSidebarConnection", "viewTableDdl"];
|
||||
|
||||
it("registers pagination navigation as unassigned grid shortcuts", () => {
|
||||
const paginationActions = [
|
||||
["goToFirstPage", "settings.shortcutGoToFirstPage"],
|
||||
["goToPreviousPage", "settings.shortcutGoToPreviousPage"],
|
||||
["goToNextPage", "settings.shortcutGoToNextPage"],
|
||||
["goToLastPage", "settings.shortcutGoToLastPage"],
|
||||
] as const;
|
||||
|
||||
for (const [id, labelKey] of paginationActions) {
|
||||
expect(SHORTCUT_DEFINITIONS.find((item) => item.id === id)).toMatchObject({ id, labelKey, scope: "grid", defaultShortcut: "" });
|
||||
expect(DEFAULT_SHORTCUT_SETTINGS[id]).toBe("");
|
||||
}
|
||||
});
|
||||
|
||||
it("normalizes missing, legacy, cleared, and configured pagination shortcuts", () => {
|
||||
const missing = normalizeShortcutSettings();
|
||||
const legacy = normalizeShortcutSettings({ goToColumn: "Mod+G" });
|
||||
const configured = normalizeShortcutSettings({ goToFirstPage: "Alt+F1", goToPreviousPage: "Alt+F2", goToNextPage: "Alt+F3", goToLastPage: "Alt+F4" });
|
||||
|
||||
for (const actionId of ["goToFirstPage", "goToPreviousPage", "goToNextPage", "goToLastPage"] as const) {
|
||||
expect(missing[actionId]).toBe("");
|
||||
expect(legacy[actionId]).toBe("");
|
||||
}
|
||||
expect(configured.goToFirstPage).toBe("Alt+F1");
|
||||
expect(configured.goToPreviousPage).toBe("Alt+F2");
|
||||
expect(configured.goToNextPage).toBe("Alt+F3");
|
||||
expect(configured.goToLastPage).toBe("Alt+F4");
|
||||
expect(configured.goToColumn).toBe("");
|
||||
});
|
||||
|
||||
it("detects pagination shortcut conflicts in the grid scope", () => {
|
||||
const shortcuts = normalizeShortcutSettings({ goToFirstPage: "Alt+F1", goToPreviousPage: "Alt+F1" });
|
||||
|
||||
expect(findShortcutConflict("goToFirstPage", shortcuts.goToFirstPage, shortcuts)).toBe("goToPreviousPage");
|
||||
expect(findShortcutConflict("goToFirstPage", "Mod+F", shortcuts)).toBeNull();
|
||||
});
|
||||
|
||||
it("registers go to column as an unassigned grid shortcut", () => {
|
||||
const definition = SHORTCUT_DEFINITIONS.find((item) => item.id === "goToColumn");
|
||||
|
||||
|
||||
@@ -211,6 +211,22 @@ export function isGoToColumnShortcut(event: ShortcutLikeEvent, shortcuts?: Parti
|
||||
return matchesShortcut(event, actionShortcut("goToColumn", shortcuts));
|
||||
}
|
||||
|
||||
export function isGoToFirstPageShortcut(event: ShortcutLikeEvent, shortcuts?: Partial<ShortcutSettings>): boolean {
|
||||
return matchesShortcut(event, actionShortcut("goToFirstPage", shortcuts));
|
||||
}
|
||||
|
||||
export function isGoToPreviousPageShortcut(event: ShortcutLikeEvent, shortcuts?: Partial<ShortcutSettings>): boolean {
|
||||
return matchesShortcut(event, actionShortcut("goToPreviousPage", shortcuts));
|
||||
}
|
||||
|
||||
export function isGoToNextPageShortcut(event: ShortcutLikeEvent, shortcuts?: Partial<ShortcutSettings>): boolean {
|
||||
return matchesShortcut(event, actionShortcut("goToNextPage", shortcuts));
|
||||
}
|
||||
|
||||
export function isGoToLastPageShortcut(event: ShortcutLikeEvent, shortcuts?: Partial<ShortcutSettings>): boolean {
|
||||
return matchesShortcut(event, actionShortcut("goToLastPage", shortcuts));
|
||||
}
|
||||
|
||||
export function isCancelSearchShortcut(event: ShortcutLikeEvent, shortcuts?: Partial<ShortcutSettings>): boolean {
|
||||
return matchesShortcut(event, actionShortcut("cancelSearch", shortcuts));
|
||||
}
|
||||
|
||||
@@ -31,6 +31,10 @@ export type ShortcutActionId =
|
||||
| "copyCurrentRow"
|
||||
| "deleteCurrentRow"
|
||||
| "goToColumn"
|
||||
| "goToFirstPage"
|
||||
| "goToPreviousPage"
|
||||
| "goToNextPage"
|
||||
| "goToLastPage"
|
||||
| "newQuery"
|
||||
| "openSettings"
|
||||
| "closeTab"
|
||||
@@ -287,6 +291,30 @@ export const SHORTCUT_DEFINITIONS: ShortcutDefinition[] = [
|
||||
scope: "grid",
|
||||
defaultShortcut: "",
|
||||
},
|
||||
{
|
||||
id: "goToFirstPage",
|
||||
labelKey: "settings.shortcutGoToFirstPage",
|
||||
scope: "grid",
|
||||
defaultShortcut: "",
|
||||
},
|
||||
{
|
||||
id: "goToPreviousPage",
|
||||
labelKey: "settings.shortcutGoToPreviousPage",
|
||||
scope: "grid",
|
||||
defaultShortcut: "",
|
||||
},
|
||||
{
|
||||
id: "goToNextPage",
|
||||
labelKey: "settings.shortcutGoToNextPage",
|
||||
scope: "grid",
|
||||
defaultShortcut: "",
|
||||
},
|
||||
{
|
||||
id: "goToLastPage",
|
||||
labelKey: "settings.shortcutGoToLastPage",
|
||||
scope: "grid",
|
||||
defaultShortcut: "",
|
||||
},
|
||||
{
|
||||
id: "newQuery",
|
||||
labelKey: "settings.shortcutNewQuery",
|
||||
|
||||
Reference in new issue
Block a user