From 0611f9f8562be82f93c8a06d9c54e50953be5e71 Mon Sep 17 00:00:00 2001 From: LemonSchneid <122685409+LemonSchneid@users.noreply.github.com> Date: Thu, 13 Aug 2026 18:59:16 -0600 Subject: [PATCH] fix(desktop): retain HUD composer focus Keep the native HUD window mouse-solid while focus is inside the rich composer. On Windows this prevents click-through from reactivating the app beneath the HUD, stealing the caret, and collapsing the transcript. --- .../desktop/src/app/hud/click-through.test.ts | 18 ++++++++++++++++-- apps/desktop/src/app/hud/click-through.ts | 19 ++++++++++++------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/apps/desktop/src/app/hud/click-through.test.ts b/apps/desktop/src/app/hud/click-through.test.ts index 45e789492d..2e12553da2 100644 --- a/apps/desktop/src/app/hud/click-through.test.ts +++ b/apps/desktop/src/app/hud/click-through.test.ts @@ -14,6 +14,7 @@ function hud() { shell.setAttribute('data-hud-shell', '') const bar = document.createElement('input') + bar.setAttribute('data-slot', 'composer-rich-input') const overlay = document.createElement('div') overlay.setAttribute('role', 'dialog') @@ -45,10 +46,23 @@ describe('hudIgnoresMouse', () => { expect(hudIgnoresMouse(shell, overlay, null, true)).toBe(false) }) - it('does not pin the window just because the composer holds the caret', () => { + it('keeps the native HUD window solid while the composer holds the caret', () => { const { bar, mount, shell } = hud() - expect(hudIgnoresMouse(shell, mount, bar, true)).toBe(true) + // On Windows, making the native window click-through while its editor owns + // focus can immediately hand the mouse activation back to the app below. + // The caret then flashes, focus leaves, and the transcript collapses before + // the user can read it. + expect(hudIgnoresMouse(shell, mount, bar, true)).toBe(false) + }) + + it('keeps the native HUD window solid while focus is inside the composer editor', () => { + const { bar, mount, shell } = hud() + const editable = document.createElement('span') + editable.contentEditable = 'true' + bar.append(editable) + + expect(hudIgnoresMouse(shell, mount, editable, true)).toBe(false) }) it('pins the window while a portalled overlay holds focus, so an outside click can dismiss it', () => { diff --git a/apps/desktop/src/app/hud/click-through.ts b/apps/desktop/src/app/hud/click-through.ts index 9ab21e5c3e..669f093fd7 100644 --- a/apps/desktop/src/app/hud/click-through.ts +++ b/apps/desktop/src/app/hud/click-through.ts @@ -15,10 +15,10 @@ import { type RefObject, useEffect } from 'react' * - Focus BESIDE the shell is a portalled dialog, popover or menu, and it owns * the next click — including the one outside itself that dismisses it, which * the hit test cannot see coming. That pins the window solid. - * - Focus INSIDE the shell does not. The composer holding the caret is the - * HUD's resting state rather than a claim on the whole rectangle, and reading - * it as one is what made an engaged HUD eat every click in its own empty - * space — on a fresh thread, the entire window. + * - Focus INSIDE the shell is normally the HUD's resting state — except for + * the composer caret. On Windows the native window must stay solid while the + * editor owns focus: making it click-through can immediately reactivate the + * application underneath, steal the caret, and collapse the transcript. */ export function hudIgnoresMouse( root: Element, @@ -34,11 +34,16 @@ export function hudIgnoresMouse( } const overSomething = hit !== null && !hit.contains(root) - // `windowFocused` is what stops a stale `active` — the composer keeps focus - // after you click away to another app — pinning the HUD solid forever. + + const composerFocused = + windowFocused && + active !== null && + root.contains(active) && + active.closest('[data-slot="composer-rich-input"]') !== null + const overlayFocused = windowFocused && active !== null && !root.contains(active) && !active.contains(root) - return !overSomething && !overlayFocused + return !composerFocused && !overSomething && !overlayFocused } /**