Restore input focus after Cmd+K and focus input on agent switch

This commit is contained in:
Mohamed Boudra
2026-02-04 11:27:04 +07:00
parent cec9e3b42b
commit bceac42ec9
3 changed files with 81 additions and 2 deletions
+18 -1
View File
@@ -6,11 +6,14 @@ interface KeyboardNavState {
cmdOrCtrlDown: boolean;
/** Sidebar-visible agent keys (up to 9), in top-to-bottom visual order. */
sidebarShortcutAgentKeys: string[];
focusChatInputRequest: { id: number; agentKey: string | null } | null;
setCommandCenterOpen: (open: boolean) => void;
setAltDown: (down: boolean) => void;
setCmdOrCtrlDown: (down: boolean) => void;
setSidebarShortcutAgentKeys: (keys: string[]) => void;
requestFocusChatInput: (agentKey: string | null) => void;
clearFocusChatInputRequest: (id: number) => void;
resetModifiers: () => void;
}
@@ -19,11 +22,25 @@ export const useKeyboardNavStore = create<KeyboardNavState>((set) => ({
altDown: false,
cmdOrCtrlDown: false,
sidebarShortcutAgentKeys: [],
focusChatInputRequest: null,
setCommandCenterOpen: (open) => set({ commandCenterOpen: open }),
setAltDown: (down) => set({ altDown: down }),
setCmdOrCtrlDown: (down) => set({ cmdOrCtrlDown: down }),
setSidebarShortcutAgentKeys: (keys) => set({ sidebarShortcutAgentKeys: keys }),
requestFocusChatInput: (agentKey) =>
set((state) => ({
focusChatInputRequest: {
id: (state.focusChatInputRequest?.id ?? 0) + 1,
agentKey,
},
})),
clearFocusChatInputRequest: (id) =>
set((state) => {
if (state.focusChatInputRequest?.id !== id) {
return state;
}
return { focusChatInputRequest: null };
}),
resetModifiers: () => set({ altDown: false, cmdOrCtrlDown: false }),
}));