Fix Cmd+K focus restore and focus input after agent switch

This commit is contained in:
Mohamed Boudra
2026-02-04 11:32:28 +07:00
parent bceac42ec9
commit 1be891e21c
4 changed files with 46 additions and 16 deletions
@@ -127,7 +127,19 @@ export function useGlobalKeyboardNav({
if ((event.metaKey || event.ctrlKey) && lowerKey === "k") {
event.preventDefault();
const s = useKeyboardNavStore.getState();
s.setCommandCenterOpen(!s.commandCenterOpen);
if (!s.commandCenterOpen) {
const target = event.target as unknown;
const el =
typeof HTMLElement !== "undefined" && target instanceof HTMLElement
? target
: (typeof document !== "undefined"
? (document.activeElement as HTMLElement | null)
: null);
s.setFocusRestoreElement(el);
s.setCommandCenterOpen(true);
} else {
s.setCommandCenterOpen(false);
}
return;
}