1 parent
2f464e0d33
commit
44dc2a88f8
14 files changed
+334
-2
No files matched your search
@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
eventToModifierOnlyShortcut,
|
||||
eventToShortcut,
|
||||
isEditTableStructureShortcut,
|
||||
isExecuteSqlInNewResultTabShortcut,
|
||||
isGoToColumnShortcut,
|
||||
isGoToFirstPageShortcut,
|
||||
@@ -107,6 +108,19 @@ describe("keyboard shortcut matching", () => {
|
||||
expect(isGoToColumnShortcut({ key: "g", ctrlKey: true, isComposing: true }, { goToColumn: "Mod+G" })).toBe(false);
|
||||
});
|
||||
|
||||
it("matches the edit-table-structure shortcut on Windows and macOS", () => {
|
||||
expect(isEditTableStructureShortcut({ key: "d", ctrlKey: true }, undefined, "Win32")).toBe(true);
|
||||
expect(isEditTableStructureShortcut({ key: "d", metaKey: true }, undefined, "MacIntel")).toBe(true);
|
||||
expect(isEditTableStructureShortcut({ key: "d", ctrlKey: true }, undefined, "MacIntel")).toBe(false);
|
||||
});
|
||||
|
||||
it("honors custom and disabled edit-table-structure shortcuts", () => {
|
||||
expect(isEditTableStructureShortcut({ key: "e", ctrlKey: true, shiftKey: true }, { editTableStructure: "Shift+Mod+E" }, "Win32")).toBe(true);
|
||||
expect(isEditTableStructureShortcut({ key: "d", ctrlKey: true }, { editTableStructure: "Shift+Mod+E" }, "Win32")).toBe(false);
|
||||
expect(isEditTableStructureShortcut({ key: "d", ctrlKey: true }, { editTableStructure: "" }, "Win32")).toBe(false);
|
||||
expect(isEditTableStructureShortcut({ key: "d", ctrlKey: true, isComposing: true }, undefined, "Win32")).toBe(false);
|
||||
});
|
||||
|
||||
it.each([
|
||||
["goToFirstPage", isGoToFirstPageShortcut, "F1"],
|
||||
["goToPreviousPage", isGoToPreviousPageShortcut, "F2"],
|
||||
|
||||
@@ -83,10 +83,32 @@ describe("shortcutRegistry editor actions", () => {
|
||||
it("detects go-to-column conflicts only within the grid scope", () => {
|
||||
const shortcuts = normalizeShortcutSettings({ goToColumn: "Mod+D" });
|
||||
|
||||
expect(findShortcutConflict("goToColumn", shortcuts.goToColumn, shortcuts)).toBe("copyCurrentRow");
|
||||
expect(findShortcutConflict("goToColumn", shortcuts.goToColumn, shortcuts)).toBe("editTableStructure");
|
||||
expect(findShortcutConflict("goToColumn", "Mod+F", shortcuts)).toBeNull();
|
||||
});
|
||||
|
||||
it("registers edit table structure as the conflict-free default Mod+D grid action", () => {
|
||||
const definition = SHORTCUT_DEFINITIONS.find((item) => item.id === "editTableStructure");
|
||||
|
||||
expect(definition).toMatchObject({
|
||||
labelKey: "settings.shortcutEditTableStructure",
|
||||
scope: "grid",
|
||||
defaultShortcut: "Mod+D",
|
||||
});
|
||||
expect(DEFAULT_SHORTCUT_SETTINGS.editTableStructure).toBe("Mod+D");
|
||||
expect(DEFAULT_SHORTCUT_SETTINGS.copyCurrentRow).toBe("");
|
||||
expect(findShortcutConflict("editTableStructure", DEFAULT_SHORTCUT_SETTINGS.editTableStructure, DEFAULT_SHORTCUT_SETTINGS)).toBeNull();
|
||||
expect(findShortcutConflict("duplicateLine", DEFAULT_SHORTCUT_SETTINGS.duplicateLine, DEFAULT_SHORTCUT_SETTINGS)).toBeNull();
|
||||
});
|
||||
|
||||
it("migrates the legacy copy-row Mod+D default without overwriting explicit shortcuts", () => {
|
||||
expect(normalizeShortcutSettings()).toMatchObject({ editTableStructure: "Mod+D", copyCurrentRow: "" });
|
||||
expect(normalizeShortcutSettings({ copyCurrentRow: "Mod+D" })).toMatchObject({ editTableStructure: "Mod+D", copyCurrentRow: "" });
|
||||
expect(normalizeShortcutSettings({ copyCurrentRow: "Shift+Mod+C" })).toMatchObject({ editTableStructure: "Mod+D", copyCurrentRow: "Shift+Mod+C" });
|
||||
expect(normalizeShortcutSettings({ editTableStructure: "", copyCurrentRow: "Mod+D" })).toMatchObject({ editTableStructure: "", copyCurrentRow: "Mod+D" });
|
||||
expect(normalizeShortcutSettings({ editTableStructure: "Shift+Mod+D", copyCurrentRow: "Mod+D" })).toMatchObject({ editTableStructure: "Shift+Mod+D", copyCurrentRow: "Mod+D" });
|
||||
});
|
||||
|
||||
it("registers the new-data-tab mouse modifier as a configurable sidebar shortcut", () => {
|
||||
const definition = SHORTCUT_DEFINITIONS.find((item) => item.id === "openDataInNewTab");
|
||||
|
||||
|
||||
@@ -203,6 +203,10 @@ export function isCopyCurrentRowShortcut(event: ShortcutLikeEvent, shortcuts?: P
|
||||
return matchesShortcut(event, actionShortcut("copyCurrentRow", shortcuts));
|
||||
}
|
||||
|
||||
export function isEditTableStructureShortcut(event: ShortcutLikeEvent, shortcuts?: Partial<ShortcutSettings>, platform = globalThis.navigator?.platform || ""): boolean {
|
||||
return matchesShortcut(event, actionShortcut("editTableStructure", shortcuts, platform), platform);
|
||||
}
|
||||
|
||||
export function isDeleteCurrentRowShortcut(event: ShortcutLikeEvent, shortcuts?: Partial<ShortcutSettings>): boolean {
|
||||
return matchesShortcut(event, actionShortcut("deleteCurrentRow", shortcuts));
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ export type ShortcutActionId =
|
||||
| "lowercaseSelection"
|
||||
| "exPasteSqlInCondition"
|
||||
| "toggleFold"
|
||||
| "editTableStructure"
|
||||
| "copyCurrentRow"
|
||||
| "deleteCurrentRow"
|
||||
| "goToColumn"
|
||||
@@ -108,6 +109,7 @@ const PLATFORM_DEFAULT_SHORTCUTS: Partial<Record<ShortcutActionId, ReadonlySet<s
|
||||
navigateTabHistoryForward: new Set(["Ctrl+Alt+ArrowRight", "Mod+Alt+ArrowRight"]),
|
||||
};
|
||||
const LEGACY_CLOSE_TAB_DEFAULT = "Meta+W";
|
||||
const LEGACY_COPY_CURRENT_ROW_DEFAULT = "Mod+D";
|
||||
const TAB_NAVIGATION_HISTORY_ACTIONS: ShortcutActionId[] = ["navigateTabHistoryBack", "navigateTabHistoryForward"];
|
||||
|
||||
export const SHORTCUT_DEFINITIONS: ShortcutDefinition[] = [
|
||||
@@ -273,11 +275,17 @@ export const SHORTCUT_DEFINITIONS: ShortcutDefinition[] = [
|
||||
scope: "editor",
|
||||
defaultShortcut: "Mod+.",
|
||||
},
|
||||
{
|
||||
id: "editTableStructure",
|
||||
labelKey: "settings.shortcutEditTableStructure",
|
||||
scope: "grid",
|
||||
defaultShortcut: "Mod+D",
|
||||
},
|
||||
{
|
||||
id: "copyCurrentRow",
|
||||
labelKey: "settings.shortcutCopyCurrentRow",
|
||||
scope: "grid",
|
||||
defaultShortcut: "Mod+D",
|
||||
defaultShortcut: "",
|
||||
},
|
||||
{
|
||||
id: "deleteCurrentRow",
|
||||
@@ -591,6 +599,11 @@ export function normalizeShortcutSettings(settings?: Partial<ShortcutSettings>,
|
||||
}),
|
||||
) as ShortcutSettings;
|
||||
|
||||
if (!hasExplicitShortcut(settings, "editTableStructure") && settings?.copyCurrentRow === LEGACY_COPY_CURRENT_ROW_DEFAULT) {
|
||||
normalized.editTableStructure = LEGACY_COPY_CURRENT_ROW_DEFAULT;
|
||||
normalized.copyCurrentRow = "";
|
||||
}
|
||||
|
||||
for (const actionId of TAB_NAVIGATION_HISTORY_ACTIONS) {
|
||||
if (hasExplicitShortcut(settings, actionId)) continue;
|
||||
const definition = SHORTCUT_DEFINITIONS.find((item) => item.id === actionId);
|
||||
|
||||
Reference in new issue
Block a user