From 232426ced231e8a76dba0203414b6f423132d7ff Mon Sep 17 00:00:00 2001 From: zipg Date: Fri, 4 Sep 2026 02:05:07 +0800 Subject: [PATCH] fix(grid): restore copy current row Mod+D shortcut --- .../editor/keyboardShortcuts.spec.ts | 5 +++-- .../__tests__/editor/shortcutRegistry.spec.ts | 20 ++++++++++--------- .../src/lib/editor/shortcutRegistry.ts | 11 +++++----- packages/app-tests/keyboardShortcuts.test.ts | 4 ++-- packages/app-tests/settingsStore.test.ts | 4 ++-- 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/apps/desktop/src/lib/__tests__/editor/keyboardShortcuts.spec.ts b/apps/desktop/src/lib/__tests__/editor/keyboardShortcuts.spec.ts index 67b6b7412c..4cd87c57e9 100644 --- a/apps/desktop/src/lib/__tests__/editor/keyboardShortcuts.spec.ts +++ b/apps/desktop/src/lib/__tests__/editor/keyboardShortcuts.spec.ts @@ -125,8 +125,9 @@ describe("keyboard shortcut matching", () => { }); 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, shiftKey: true }, undefined, "Win32")).toBe(true); + expect(isEditTableStructureShortcut({ key: "d", metaKey: true, shiftKey: true }, undefined, "MacIntel")).toBe(true); + expect(isEditTableStructureShortcut({ key: "d", ctrlKey: true }, undefined, "Win32")).toBe(false); expect(isEditTableStructureShortcut({ key: "d", ctrlKey: true }, undefined, "MacIntel")).toBe(false); }); diff --git a/apps/desktop/src/lib/__tests__/editor/shortcutRegistry.spec.ts b/apps/desktop/src/lib/__tests__/editor/shortcutRegistry.spec.ts index 6df0648def..011eb677b3 100644 --- a/apps/desktop/src/lib/__tests__/editor/shortcutRegistry.spec.ts +++ b/apps/desktop/src/lib/__tests__/editor/shortcutRegistry.spec.ts @@ -96,30 +96,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("editTableStructure"); + expect(findShortcutConflict("goToColumn", shortcuts.goToColumn, shortcuts)).toBe("copyCurrentRow"); expect(findShortcutConflict("goToColumn", "Mod+F", shortcuts)).toBeNull(); }); - it("registers edit table structure as the conflict-free default Mod+D grid action", () => { + it("registers copy-current-row Mod+D and edit-table-structure Mod+Shift+D as conflict-free grid defaults", () => { const definition = SHORTCUT_DEFINITIONS.find((item) => item.id === "editTableStructure"); expect(definition).toMatchObject({ labelKey: "settings.shortcutEditTableStructure", scope: "grid", - defaultShortcut: "Mod+D", + defaultShortcut: "Mod+Shift+D", }); - expect(DEFAULT_SHORTCUT_SETTINGS.editTableStructure).toBe("Mod+D"); - expect(DEFAULT_SHORTCUT_SETTINGS.copyCurrentRow).toBe(""); + expect(DEFAULT_SHORTCUT_SETTINGS.editTableStructure).toBe("Mod+Shift+D"); + expect(DEFAULT_SHORTCUT_SETTINGS.copyCurrentRow).toBe("Mod+D"); expect(findShortcutConflict("editTableStructure", DEFAULT_SHORTCUT_SETTINGS.editTableStructure, DEFAULT_SHORTCUT_SETTINGS)).toBeNull(); + expect(findShortcutConflict("copyCurrentRow", DEFAULT_SHORTCUT_SETTINGS.copyCurrentRow, 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" }); + it("restores copy-current-row Mod+D after the previous edit-structure migration", () => { + expect(normalizeShortcutSettings()).toMatchObject({ editTableStructure: "Mod+Shift+D", copyCurrentRow: "Mod+D" }); + expect(normalizeShortcutSettings({ copyCurrentRow: "Mod+D" })).toMatchObject({ editTableStructure: "Mod+Shift+D", copyCurrentRow: "Mod+D" }); + expect(normalizeShortcutSettings({ copyCurrentRow: "Shift+Mod+C" })).toMatchObject({ editTableStructure: "Mod+Shift+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" }); + expect(normalizeShortcutSettings({ editTableStructure: "Mod+D", copyCurrentRow: "" })).toMatchObject({ editTableStructure: "Mod+Shift+D", copyCurrentRow: "Mod+D" }); }); it("registers the new-data-tab mouse modifier as a configurable sidebar shortcut", () => { diff --git a/apps/desktop/src/lib/editor/shortcutRegistry.ts b/apps/desktop/src/lib/editor/shortcutRegistry.ts index de90e4feb4..51f30ae1f8 100644 --- a/apps/desktop/src/lib/editor/shortcutRegistry.ts +++ b/apps/desktop/src/lib/editor/shortcutRegistry.ts @@ -126,6 +126,7 @@ const PLATFORM_DEFAULT_SHORTCUTS: Partial, }), ) as ShortcutSettings; - if (!hasExplicitShortcut(settings, "editTableStructure") && settings?.copyCurrentRow === LEGACY_COPY_CURRENT_ROW_DEFAULT) { - normalized.editTableStructure = LEGACY_COPY_CURRENT_ROW_DEFAULT; - normalized.copyCurrentRow = ""; + if (settings?.copyCurrentRow === "" && settings?.editTableStructure === LEGACY_COPY_CURRENT_ROW_DEFAULT) { + normalized.editTableStructure = EDIT_TABLE_STRUCTURE_DEFAULT; + normalized.copyCurrentRow = LEGACY_COPY_CURRENT_ROW_DEFAULT; } for (const actionId of TAB_NAVIGATION_HISTORY_ACTIONS) { diff --git a/packages/app-tests/keyboardShortcuts.test.ts b/packages/app-tests/keyboardShortcuts.test.ts index 3a3cf1e268..9253b78204 100644 --- a/packages/app-tests/keyboardShortcuts.test.ts +++ b/packages/app-tests/keyboardShortcuts.test.ts @@ -392,8 +392,8 @@ test("matches Cmd+S for saving", () => { assert.equal(isSaveShortcut({ key: "s", metaKey: true }), true); }); -test("leaves copy current row disabled by default while honoring custom shortcuts", () => { - assert.equal(isCopyCurrentRowShortcut({ key: "d", metaKey: true }), false); +test("matches copy current row Mod+D by default while honoring custom shortcuts", () => { + assert.equal(isCopyCurrentRowShortcut({ key: "d", metaKey: true }), true); assert.equal(isCopyCurrentRowShortcut({ key: "d", altKey: true }, { copyCurrentRow: "Alt+D" }), true); }); diff --git a/packages/app-tests/settingsStore.test.ts b/packages/app-tests/settingsStore.test.ts index 7aa032cadf..2ba99b19ba 100644 --- a/packages/app-tests/settingsStore.test.ts +++ b/packages/app-tests/settingsStore.test.ts @@ -412,8 +412,8 @@ test("defaults shortcut settings", () => { assert.equal(settings.shortcuts.executeSql, "Mod+Enter"); assert.equal(settings.shortcuts.saveSql, "Mod+S"); assert.equal(settings.shortcuts.extendSelection, "Alt+W"); - assert.equal(settings.shortcuts.editTableStructure, "Mod+D"); - assert.equal(settings.shortcuts.copyCurrentRow, ""); + assert.equal(settings.shortcuts.editTableStructure, "Mod+Shift+D"); + assert.equal(settings.shortcuts.copyCurrentRow, "Mod+D"); assert.equal(settings.shortcuts.deleteCurrentRow, "Delete"); assert.equal(settings.shortcuts.goToFirstPage, ""); assert.equal(settings.shortcuts.goToPreviousPage, "");