mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
Focus Agent Input (⌘L / Ctrl+L) only worked while focus was already in a task view. It now also focuses the message input of the task shown in an editor tab or the Agents tool window (the one used last when several are shown) from anywhere that doesn't own the key: in a code editor ⌘L stays Go to Line, the terminal keeps Ctrl+L, and popups and dialogs keep focus. Inside a task view it still wins over the editor. Co-authored-by: Mr0Bread <55754540+Mr0Bread@users.noreply.github.com>
41 lines
1.4 KiB
TypeScript
41 lines
1.4 KiB
TypeScript
/** The agent session holding focus, and those shown elsewhere, for actions scoped to a task view. */
|
|
import { setContext } from "@/platform/context";
|
|
|
|
export interface FocusedSession {
|
|
openFind(): void;
|
|
focusInput?: () => void;
|
|
}
|
|
|
|
let focused: FocusedSession | null = null;
|
|
/** Sessions on screen that accept input, least recently focused first. */
|
|
let reachable: FocusedSession[] = [];
|
|
|
|
/** The session `Focus Agent Input` targets: the focused one, else the most recently used shown one. */
|
|
export function inputSession(): FocusedSession | null {
|
|
if (focused) return focused.focusInput ? focused : null;
|
|
return reachable.at(-1) ?? null;
|
|
}
|
|
|
|
function publish() {
|
|
setContext("agentSessionFocus", !!focused);
|
|
setContext("agentInputAvailable", !!inputSession());
|
|
}
|
|
|
|
export function setFocusedSession(session: FocusedSession | null) {
|
|
focused = session;
|
|
if (session && reachable.includes(session)) reachable = [...reachable.filter((s) => s !== session), session];
|
|
publish();
|
|
}
|
|
|
|
/** Lists a shown session that accepts input as a target for the shortcut; returns a disposer. */
|
|
export function registerReachableSession(session: FocusedSession): () => void {
|
|
reachable = [...reachable.filter((s) => s !== session), session];
|
|
publish();
|
|
return () => {
|
|
reachable = reachable.filter((s) => s !== session);
|
|
publish();
|
|
};
|
|
}
|
|
|
|
export const focusedSession = () => focused;
|