From 9118406de356e7979c25209643c29c9488a9564a Mon Sep 17 00:00:00 2001 From: Syngnat Date: Tue, 26 May 2026 08:26:28 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(shortcuts):=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=85=A8=E5=B1=80=E5=BF=AB=E6=8D=B7=E9=94=AE=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=9C=AA=E7=94=9F=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 快捷键执行链路补齐新建数据源和打开 AI 面板动作 - 将创建数据源入口改为稳定回调,避免全局监听依赖丢失 - 补充快捷键管理器动作与实际处理逻辑一致性测试 --- frontend/src/App.tool-center.test.ts | 35 ++++++++++++++++++++++++++++ frontend/src/App.tsx | 12 +++++++--- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/frontend/src/App.tool-center.test.ts b/frontend/src/App.tool-center.test.ts index 8f1444e..92b0c08 100644 --- a/frontend/src/App.tool-center.test.ts +++ b/frontend/src/App.tool-center.test.ts @@ -7,6 +7,20 @@ const appSource = readFileSync( 'utf8', ); +const getGlobalShortcutCaseBlock = (action: string) => { + const caseToken = `case '${action}':`; + const start = appSource.indexOf(caseToken); + expect(start).toBeGreaterThan(-1); + + const afterCase = appSource.slice(start + caseToken.length); + const nextCaseIndex = afterCase.search(/\n\s+case '[^']+':/); + const switchEndIndex = afterCase.search(/\n\s+}\n\s+};\n\n\s+window\.addEventListener\('keydown', handleGlobalShortcut\);/); + const endIndex = nextCaseIndex >= 0 ? nextCaseIndex : switchEndIndex; + + expect(endIndex).toBeGreaterThan(-1); + return afterCase.slice(0, endIndex); +}; + describe('tool center menu entries', () => { it('exposes snippet management next to shortcut management', () => { expect(appSource).toContain("key: 'snippet-settings'"); @@ -97,6 +111,27 @@ describe('tool center menu entries', () => { expect(appSource).toContain('getShortcutDisplayLabel'); expect(appSource).toContain('getShortcutDisplayLabel(binding.combo, activeShortcutPlatform)'); }); + + it('executes every global shortcut action exposed in the shortcut manager', () => { + const expectedHandlers = new Map([ + ['runQuery', 'gonavi:run-active-query'], + ['focusSidebarSearch', 'gonavi:focus-sidebar-search'], + ['newQueryTab', 'handleNewQuery();'], + ['newConnection', 'handleCreateConnection();'], + ['toggleAIPanel', 'toggleAIPanel();'], + ['toggleLogPanel', 'handleToggleLogPanel();'], + ['toggleTheme', 'setTheme('], + ['openShortcutManager', 'setIsShortcutModalOpen(true);'], + ['toggleMacFullscreen', 'handleTitleBarWindowToggle();'], + ['resetWindowZoom', 'handleManualResetWindowZoom();'], + ]); + + for (const [action, handler] of expectedHandlers) { + expect(getGlobalShortcutCaseBlock(action)).toContain(handler); + } + expect(appSource).toContain('handleCreateConnection, handleManualResetWindowZoom'); + expect(appSource).toContain('setTheme, toggleAIPanel, useNativeMacWindowControls'); + }); }); describe('global appearance tokens', () => { diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 5055029..76dce9a 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -2179,11 +2179,11 @@ function App() { document.removeEventListener('mouseup', handleLogResizeUp); }; - const handleCreateConnection = () => { + const handleCreateConnection = useCallback(() => { setSecurityUpdateRepairSource(null); setEditingConnection(null); setIsModalOpen(true); - }; + }, []); const handleEditConnection = (conn: SavedConnection) => { setSecurityUpdateRepairSource(null); @@ -2675,6 +2675,12 @@ function App() { case 'newQueryTab': handleNewQuery(); break; + case 'newConnection': + handleCreateConnection(); + break; + case 'toggleAIPanel': + toggleAIPanel(); + break; case 'toggleLogPanel': handleToggleLogPanel(); break; @@ -2699,7 +2705,7 @@ function App() { return () => { window.removeEventListener('keydown', handleGlobalShortcut); }; - }, [activeShortcutPlatform, handleManualResetWindowZoom, handleNewQuery, handleTitleBarWindowToggle, handleToggleLogPanel, isMacRuntime, shortcutOptions, themeMode, setTheme, useNativeMacWindowControls]); + }, [activeShortcutPlatform, handleCreateConnection, handleManualResetWindowZoom, handleNewQuery, handleTitleBarWindowToggle, handleToggleLogPanel, isMacRuntime, shortcutOptions, themeMode, setTheme, toggleAIPanel, useNativeMacWindowControls]); useEffect(() => { if (!capturingShortcutAction) {