refactor: extract keyboard shortcut routing logic to separate module

This commit is contained in:
Mohamed Boudra
2026-02-18 19:55:00 +07:00
parent e26dcde2c8
commit f070e86746
3 changed files with 104 additions and 22 deletions
@@ -18,7 +18,6 @@ import {
} from "@/utils/new-agent-routing";
import {
buildHostAgentDetailRoute,
parseHostAgentDraftRouteFromPathname,
parseHostAgentRouteFromPathname,
parseServerIdFromPathname,
} from "@/utils/host-routes";
@@ -26,29 +25,14 @@ import {
type MessageInputKeyboardActionKind,
type KeyboardShortcutPayload,
} from "@/keyboard/actions";
import {
canToggleFileExplorerShortcut,
resolveSelectedOrRouteAgentKey,
} from "@/keyboard/keyboard-shortcut-routing";
import { resolveKeyboardShortcut } from "@/keyboard/keyboard-shortcuts";
import { resolveKeyboardFocusScope } from "@/keyboard/focus-scope";
import { getShortcutOs } from "@/utils/shortcut-platform";
function resolveSelectedOrRouteAgentKey(input: {
selectedAgentId?: string;
pathname: string;
}): string | null {
const DRAFT_AGENT_ID = "__new_agent__";
if (input.selectedAgentId) {
return input.selectedAgentId;
}
const route = parseHostAgentRouteFromPathname(input.pathname);
if (!route) {
const draftRoute = parseHostAgentDraftRouteFromPathname(input.pathname);
if (!draftRoute) {
return null;
}
return `${draftRoute.serverId}:${DRAFT_AGENT_ID}`;
}
return `${route.serverId}:${route.agentId}`;
}
export function useKeyboardShortcuts({
enabled,
isMobile,
@@ -161,7 +145,16 @@ export function useKeyboardShortcuts({
toggleAgentList();
return true;
case "sidebar.toggle.right":
if (!selectedAgentId || !toggleFileExplorer) {
if (!toggleFileExplorer) {
return false;
}
if (
!canToggleFileExplorerShortcut({
selectedAgentId,
pathname,
toggleFileExplorer,
})
) {
return false;
}
toggleFileExplorer();
@@ -234,7 +227,11 @@ export function useKeyboardShortcuts({
isTauri,
focusScope,
commandCenterOpen: store.commandCenterOpen,
hasSelectedAgent: Boolean(selectedAgentId && toggleFileExplorer),
hasSelectedAgent: canToggleFileExplorerShortcut({
selectedAgentId,
pathname,
toggleFileExplorer,
}),
},
});
if (!match) {