mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-06-06 06:29:35 +08:00
🐛 fix(shortcuts): 修复全局快捷键配置未生效
- 快捷键执行链路补齐新建数据源和打开 AI 面板动作 - 将创建数据源入口改为稳定回调,避免全局监听依赖丢失 - 补充快捷键管理器动作与实际处理逻辑一致性测试
This commit is contained in:
@@ -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', () => {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user