Skip to content

The agent that grows with you

fix(desktop): keep the composer focused while reading the HUD band

Brooklyn Nicholson0db27883388a
diff --git a/apps/desktop/src/app/hud/hud-shell.tsx b/apps/desktop/src/app/hud/hud-shell.tsx
index 8422ee9f3ad..4908494f184 100644
--- a/apps/desktop/src/app/hud/hud-shell.tsx
+++ b/apps/desktop/src/app/hud/hud-shell.tsx
@@ -17,6 +17,7 @@ import { titlebarButtonClass } from '../shell/titlebar'
import { useHudClickThrough } from './click-through'
import { useHudGlass } from './glass'
import { useHudGoto, useReportHudSession } from './handoff'
+import { useHudThreadFocus } from './thread-focus'
/** How long the transcript lingers at its glanceable opacity — after a turn
* lands, or after you let go of the composer — before it goes. This is the ONLY
@@ -308,6 +309,7 @@ export function HudShell() {
}
}, [])
+ useHudThreadFocus(rootRef)
useHudGlass(rootRef, recent || held, filled)
useHudClickThrough(rootRef)
diff --git a/apps/desktop/src/app/hud/thread-focus.ts b/apps/desktop/src/app/hud/thread-focus.ts
new file mode 100644
index 00000000000..978557eeb2c
--- /dev/null
+++ b/apps/desktop/src/app/hud/thread-focus.ts
@@ -0,0 +1,49 @@
+import { type RefObject, useEffect } from 'react'
+
+import { focusComposerInput } from '@/app/chat/composer/focus'
+import { RICH_INPUT_SLOT } from '@/app/chat/composer/rich-editor'
+
+const THREAD_INTERACTIVE = 'a[href], button, input, textarea, select, [contenteditable], [role="button"], [role="link"]'
+
+/**
+ * In HUD mode the band is for reading over another app — clicking a line is not
+ * leaving the composer. Without this, mousedown on the scrollback blurs the
+ * input, the band fades, and the focus ring vanishes mid-read.
+ */
+export function useHudThreadFocus(rootRef: RefObject<HTMLElement | null>): void {
+ useEffect(() => {
+ const root = rootRef.current
+
+ if (!root) {
+ return
+ }
+
+ const onPointerDown = (event: PointerEvent) => {
+ if (event.button !== 0) {
+ return
+ }
+
+ const target = event.target
+
+ if (!(target instanceof Element)) {
+ return
+ }
+
+ if (!target.closest('[data-slot="composer-bounds"]')) {
+ return
+ }
+
+ if (target.closest(THREAD_INTERACTIVE)) {
+ return
+ }
+
+ event.preventDefault()
+
+ focusComposerInput(root.querySelector<HTMLElement>(`[data-slot="${RICH_INPUT_SLOT}"]`))
+ }
+
+ root.addEventListener('pointerdown', onPointerDown, true)
+
+ return () => root.removeEventListener('pointerdown', onPointerDown, true)
+ }, [rootRef])
+}