From 2fee3d1389fce8aa2e0457b1c39b47ffa92a5c80 Mon Sep 17 00:00:00 2001 From: Syngnat Date: Mon, 1 Jun 2026 11:04:26 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(shortcuts):=20=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E6=96=B0=E5=BB=BA=E6=9F=A5=E8=AF=A2=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=BF=AB=E6=8D=B7=E9=94=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将新建查询页默认快捷键改为 macOS Cmd+N、Windows Ctrl+N - 将新建数据源默认快捷键顺延为 Cmd/Ctrl+Shift+N - 补充默认快捷键唯一性校验,避免动作默认撞键 --- frontend/src/utils/shortcuts.test.ts | 37 +++++++++++++++++++--------- frontend/src/utils/shortcuts.ts | 8 +++--- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/frontend/src/utils/shortcuts.test.ts b/frontend/src/utils/shortcuts.test.ts index aa696b0..1bf18c3 100644 --- a/frontend/src/utils/shortcuts.test.ts +++ b/frontend/src/utils/shortcuts.test.ts @@ -178,14 +178,27 @@ describe('shortcut defaults', () => { }); }); + it('keeps enabled default shortcuts unique per platform', () => { + for (const platform of ['mac', 'windows'] as const) { + const seen = new Map(); + Object.entries(DEFAULT_SHORTCUT_OPTIONS).forEach(([action, bindings]) => { + const binding = bindings[platform]; + if (!binding.enabled || !binding.combo) return; + const existingAction = seen.get(binding.combo); + expect(existingAction, `${platform} ${binding.combo} is shared by ${existingAction} and ${action}`).toBeUndefined(); + seen.set(binding.combo, action); + }); + } + }); + it('uses Navicat-inspired defaults separately for macOS and Windows/Linux', () => { expect(DEFAULT_SHORTCUT_OPTIONS.runQuery).toEqual({ mac: { combo: 'Meta+R', enabled: true }, windows: { combo: 'Ctrl+R', enabled: true }, }); expect(DEFAULT_SHORTCUT_OPTIONS.newQueryTab).toEqual({ - mac: { combo: 'Meta+Y', enabled: true }, - windows: { combo: 'Ctrl+Q', enabled: true }, + mac: { combo: 'Meta+N', enabled: true }, + windows: { combo: 'Ctrl+N', enabled: true }, }); expect(DEFAULT_SHORTCUT_OPTIONS.toggleLogPanel).toEqual({ mac: { combo: 'Meta+Shift+H', enabled: true }, @@ -195,8 +208,8 @@ describe('shortcut defaults', () => { it('registers connection and AI panel actions as real shortcuts', () => { expect(DEFAULT_SHORTCUT_OPTIONS.newConnection).toEqual({ - mac: { combo: 'Meta+N', enabled: true }, - windows: { combo: 'Ctrl+N', enabled: true }, + mac: { combo: 'Meta+Shift+N', enabled: true }, + windows: { combo: 'Ctrl+Shift+N', enabled: true }, }); expect(DEFAULT_SHORTCUT_OPTIONS.toggleAIPanel).toEqual({ mac: { combo: 'Meta+J', enabled: true }, @@ -215,21 +228,21 @@ describe('shortcut defaults', () => { mac: { combo: 'Ctrl+Shift+R', enabled: false }, windows: { combo: 'Ctrl+Shift+R', enabled: false }, }); - expect(options.newQueryTab.windows.combo).toBe('Ctrl+Q'); + expect(options.newQueryTab.windows.combo).toBe('Ctrl+N'); }); it('sanitizes partial platform shortcut bindings without losing defaults', () => { const options = sanitizeShortcutOptions({ newQueryTab: { - mac: { combo: 'Meta+Y', enabled: false }, + mac: { combo: 'Meta+N', enabled: false }, }, sendAIChatMessage: { windows: { combo: 'A', enabled: true }, }, }); - expect(options.newQueryTab.mac).toEqual({ combo: 'Meta+Y', enabled: false }); - expect(options.newQueryTab.windows).toEqual({ combo: 'Ctrl+Q', enabled: true }); + expect(options.newQueryTab.mac).toEqual({ combo: 'Meta+N', enabled: false }); + expect(options.newQueryTab.windows).toEqual({ combo: 'Ctrl+N', enabled: true }); expect(options.saveQuery.windows).toEqual({ combo: 'Ctrl+S', enabled: true }); expect(options.sendAIChatMessage.windows).toEqual({ combo: 'Enter', enabled: true }); }); @@ -237,13 +250,13 @@ describe('shortcut defaults', () => { it('resolves and displays platform-specific bindings', () => { const options = sanitizeShortcutOptions({ newQueryTab: { - mac: { combo: 'Meta+Y', enabled: true }, - windows: { combo: 'Ctrl+Q', enabled: true }, + mac: { combo: 'Meta+N', enabled: true }, + windows: { combo: 'Ctrl+N', enabled: true }, }, }); expect(resolveShortcutBinding(options, 'newQueryTab', 'mac')).toEqual({ - combo: 'Meta+Y', + combo: 'Meta+N', enabled: true, }); expect(getShortcutDisplayLabel('Meta+N', 'mac')).toBe('⌘N'); @@ -257,7 +270,7 @@ describe('shortcut defaults', () => { expect(getPrimaryShortcutDisplayLabel('C', 'windows')).toBe('Ctrl+C'); expect(getPrimaryShortcutDisplayLabel('Enter', 'mac')).toBe('⌘↵'); expect(getPrimaryShortcutDisplayLabel('Enter', 'windows')).toBe('Ctrl+Enter'); - expect(resolveShortcutDisplay(options, 'newQueryTab', 'windows')).toBe('Ctrl+Q'); + expect(resolveShortcutDisplay(options, 'newQueryTab', 'windows')).toBe('Ctrl+N'); }); }); diff --git a/frontend/src/utils/shortcuts.ts b/frontend/src/utils/shortcuts.ts index 68ffb11..7308469 100644 --- a/frontend/src/utils/shortcuts.ts +++ b/frontend/src/utils/shortcuts.ts @@ -191,13 +191,13 @@ export const DEFAULT_SHORTCUT_OPTIONS: ShortcutOptions = { windows: { combo: 'Ctrl+K', enabled: true }, }, newQueryTab: { - mac: { combo: 'Meta+Y', enabled: true }, - windows: { combo: 'Ctrl+Q', enabled: true }, - }, - newConnection: { mac: { combo: 'Meta+N', enabled: true }, windows: { combo: 'Ctrl+N', enabled: true }, }, + newConnection: { + mac: { combo: 'Meta+Shift+N', enabled: true }, + windows: { combo: 'Ctrl+Shift+N', enabled: true }, + }, toggleAIPanel: { mac: { combo: 'Meta+J', enabled: true }, windows: { combo: 'Ctrl+J', enabled: true },