The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): keep background tabs out of blur, timeline, and key routing
Brooklyn Nicholson771dfcc083b4
diff --git a/apps/desktop/src/app/chat/composer/focus.ts b/apps/desktop/src/app/chat/composer/focus.tsindex a470edfcd95..7120fde2b1a 100644--- a/apps/desktop/src/app/chat/composer/focus.ts+++ b/apps/desktop/src/app/chat/composer/focus.ts@@ -10,6 +10,8 @@* steal focus from the composer effect.*/+import { queryVisible } from '@/components/pane-shell/pane-visibility'+import type { InlineRefInput } from './inline-refs'import { RICH_INPUT_SLOT } from './rich-editor'@@ -175,9 +177,11 @@ export const focusComposerInput = (el: HTMLElement | null) => {window.setTimeout(focus, 0)}-/** Drop focus from the main composer input (status-stack chrome, sidebar, etc.). */+/** Drop focus from the main composer input (status-stack chrome, sidebar, etc.).+ * Skips inactive tabs — they stay mounted, so an unscoped lookup can land on a+ * background composer and leave the visible one focused. */export const blurComposerInput = () => {- const el = document.querySelector(`[data-slot="${RICH_INPUT_SLOT}"]`) as HTMLElement | null+ const el = queryVisible(`[data-slot="${RICH_INPUT_SLOT}"]`)if (el && document.activeElement === el) {el.blur()diff --git a/apps/desktop/src/components/assistant-ui/thread/timeline.tsx b/apps/desktop/src/components/assistant-ui/thread/timeline.tsxindex 18b09c63fe3..b1603076e5f 100644--- a/apps/desktop/src/components/assistant-ui/thread/timeline.tsx+++ b/apps/desktop/src/components/assistant-ui/thread/timeline.tsx@@ -101,8 +101,15 @@ function jumpScroll(viewport: HTMLElement, top: number, duration = 170): void {jumpRaf = requestAnimationFrame(step)}-function scrollToPrompt(id: string) {- const viewport = document.querySelector<HTMLElement>(VIEWPORT)+// A timeline belongs to ONE chat surface, and several are mounted at once — side+// by side in a split, and stacked (hidden but kept alive) as inactive tabs. Walk+// up to this timeline's own surface before looking for the viewport; a+// document-wide lookup scrolls somebody else's thread.+export const ownViewport = (root: HTMLElement | null): HTMLElement | null =>+ (root?.closest('[data-session-anchor]') ?? document).querySelector<HTMLElement>(VIEWPORT)++function scrollToPrompt(root: HTMLElement | null, id: string) {+ const viewport = ownViewport(root)const node = viewport?.querySelector<HTMLElement>(`[data-message-id="${CSS.escape(id)}"]`)if (!viewport || !node) {@@ -139,6 +146,8 @@ export const ThreadTimeline: FC = () => {const [activeIndex, setActiveIndex] = useState(0)const [open, setOpen] = useState(false)const closeTimerRef = useRef<number | undefined>(undefined)+ const rootRef = useRef<HTMLDivElement | null>(null)+ const jump = useCallback((id: string) => scrollToPrompt(rootRef.current, id), [])// Hover sync lives on the DOM, not in React state — the tick and its popover// row are siblings in different subtrees, so a shared index-keyed paint() lights@@ -176,7 +185,7 @@ export const ThreadTimeline: FC = () => {useEffect(() => () => window.clearTimeout(closeTimerRef.current), [])useEffect(() => {- const viewport = document.querySelector<HTMLElement>(VIEWPORT)+ const viewport = ownViewport(rootRef.current)if (!viewport || entries.length === 0) {return@@ -236,20 +245,15 @@ export const ThreadTimeline: FC = () => {data-suppress-pane-reveal=""onMouseEnter={keepOpen}onMouseLeave={closeSoon}+ ref={rootRef}role="navigation">- <TimelineTicks- activeIndex={activeIndex}- entries={entries}- onHover={paint}- onJump={scrollToPrompt}- tickRefs={tickRefs}- />+ <TimelineTicks activeIndex={activeIndex} entries={entries} onHover={paint} onJump={jump} tickRefs={tickRefs} /><TimelinePopoveractiveIndex={activeIndex}entries={entries}onHover={paint}- onJump={scrollToPrompt}+ onJump={jump}open={open}rowRefs={rowRefs}/>diff --git a/apps/desktop/src/lib/keybinds/composer-focus-keys.ts b/apps/desktop/src/lib/keybinds/composer-focus-keys.tsindex 6bba44aa34a..29da02cda58 100644--- a/apps/desktop/src/lib/keybinds/composer-focus-keys.ts+++ b/apps/desktop/src/lib/keybinds/composer-focus-keys.ts@@ -7,6 +7,7 @@*/import { $workspaceIsPage } from '@/app/routes'+import { queryVisible } from '@/components/pane-shell/pane-visibility'import { switcherActive } from '@/store/session-switcher'import { isEditableTarget, isFocusWithin } from './combo'@@ -37,8 +38,15 @@ const ENTER_ACTIVATES = ['[role="treeitem"]'].join(',')-const BLOCKING_SURFACE =- '[role="dialog"],[role="alertdialog"],[role="menu"],[role="listbox"],[data-radix-popper-content-wrapper],[data-overlay-surface],[data-clarify-choices]'+// Overlays that cover the whole window (portaled to the body, or the overlay+// shell itself) — one anywhere means the composer is behind it.+const BLOCKING_OVERLAY =+ '[role="dialog"],[role="alertdialog"],[role="menu"],[role="listbox"],[data-radix-popper-content-wrapper],[data-overlay-surface]'++// Blockers that live INSIDE a chat surface. Inactive tabs stay mounted, so this+// one has to be visible-scoped: a clarify card waiting in a background thread+// must not take the foreground composer's letter keys.+const BLOCKING_IN_SURFACE = '[data-clarify-choices]'/** True when the focused control would normally handle Enter itself. */export function isActivateOnEnterTarget(target: EventTarget | null): boolean {@@ -59,7 +67,8 @@ export function composerFocusBlockedBySurface(): boolean {switcherActive() ||$workspaceIsPage.get() ||isFocusWithin('[data-terminal]') ||- Boolean(document.querySelector(BLOCKING_SURFACE))+ Boolean(document.querySelector(BLOCKING_OVERLAY)) ||+ Boolean(queryVisible(BLOCKING_IN_SURFACE)))}