Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(canvas): keep a hovered terminal's keyboard after the pointer leaves (sloppy focus)
reviewab1dce0d5ac3
diff --git a/CLAUDE.md b/CLAUDE.mdindex b68110ba2..640506558 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -1490,10 +1490,19 @@ session.- The xterm container is `nodrag nowheel`; a transparent **hover-guard** overlay sits on topuntil you dwell `settings.panHoverDelay` (so quick drag = move node, scroll = pan). Afterthe dwell the guard is removed and xterm takes input. The header stays draggable.-- **Click to focus** (`settings.terminalFocusFollowsPointer`, default ON = the dwell above; issue- #757, Settings → Behavior). Off, the pointer decides nothing: no dwell, and `mouseleave` no- longer blurs, re-arms or releases. A click (`HoverGuard` pointer events → `onGuardClick` → `enterNow`) or a "go to node" takes the- keyboard, and the node's active flag, presence focus AND guard then follow DOM focus. ONE hook+- **Sloppy focus** (default, `settings.terminalFocusFollowsPointer` ON): the dwell above TAKES the+ keyboard, and `mouseleave` only re-arms the guard — it never blurs the xterm or drops the active+ flag / presence focus. The terminal keeps the keyboard until another node takes it (its dwell, a+ click) or the user clicks elsewhere. This replaced strict focus-follows-mouse, where leaving the+ node released everything and typing with the pointer resting on the canvas went nowhere. Release+ follows DOM focus through the SAME hook click to focus uses (below), so a dwell onto a node whose+ ⌘M view covers its xterm blurs the OTHER terminal's xterm (`dwellBlursForeignTerminal`) — else the+ previous pane keeps eating keystrokes while another node reads as active. The guard stays a+ POINTER contract in this mode: the hook's `setArmed` is a no-op here (`focusDrivesGuard`).+- **Click to focus** (`settings.terminalFocusFollowsPointer` OFF; issue #757, Settings → Behavior):+ the pointer decides nothing: no dwell, and `mouseleave` changes nothing. A click (`HoverGuard`+ pointer events → `onGuardClick` → `enterNow`) or a "go to node" takes the keyboard, and the+ node's active flag, presence focus AND guard then follow DOM focus. ONE hookowns all of it, `nodes/useClickToFocus.ts`, and it binds to the stable `.term-node` ROOT, neverthe React Flow wrapper: focus mode MOVES that root into the fullscreen surface(`surface.appendChild(root)`), so a listener or containment check captured on the wrapper wentdiff --git a/src/renderer/components/settings/sections/BehaviorSection.tsx b/src/renderer/components/settings/sections/BehaviorSection.tsxindex c072cbf13..93462c681 100644--- a/src/renderer/components/settings/sections/BehaviorSection.tsx+++ b/src/renderer/components/settings/sections/BehaviorSection.tsx@@ -37,7 +37,7 @@ const ROWS = {panHover: { title: 'Pan-hover delay (ms)', keywords: ['pan', 'hover', 'delay', 'focus', 'guard'] },focusFollowsPointer: {title: 'Terminal focus follows pointer',- keywords: ['focus', 'hover', 'pointer', 'click', 'follows', 'x11', 'mouse', 'keyboard', 'terminal', 'mac']+ keywords: ['focus', 'hover', 'pointer', 'click', 'follows', 'x11', 'sloppy', 'mouse', 'keyboard', 'terminal', 'mac']},doubleClick: { title: 'Double-click to focus', keywords: ['double', 'click', 'focus'] },focusZoom: {@@ -211,7 +211,7 @@ export function BehaviorSection({ isActive }: { isActive: boolean }): React.JSX.label="Terminal focus follows pointer"description={settings.terminalFocusFollowsPointer- ? 'On: hovering a terminal for the pan-hover delay gives it the keyboard, and moving the pointer off it takes the keyboard away. Turn off for click to focus.'+ ? 'On: hovering a terminal for the pan-hover delay gives it the keyboard. It keeps the keyboard when the pointer moves off — until you hover another terminal, or click another node, the empty canvas or a field. Turn off for click to focus.': 'Off (click to focus): click a terminal to type in it. It keeps the keyboard until you click another node, the empty canvas or a field — moving the pointer away changes nothing.'}control={diff --git a/src/renderer/lib/terminalFocusMode.test.ts b/src/renderer/lib/terminalFocusMode.test.tsindex 848abc6f5..b54ed4ff0 100644--- a/src/renderer/lib/terminalFocusMode.test.ts+++ b/src/renderer/lib/terminalFocusMode.test.ts@@ -8,16 +8,23 @@ import {outsidePressReleases,reclaimTarget,hoverTakesKeyboard,- pointerLeaveReleases,+ pointerLeaveRearmsGuard,+ focusDrivesGuard,+ dwellBlursForeignTerminal,resolveFocusFollowsPointer} from './terminalFocusMode'/*** Issue #757 — "option to disable X Window focus-follows-pointer (Mac-style click to select what* UI element has the input focus)". A terminal node's keyboard used to follow the POINTER: a hover- * dwell took it, leaving the node took it away. `settings.terminalFocusFollowsPointer` keeps that- * (the default) or switches to click-to-focus, where the pointer decides nothing and the clicked- * terminal keeps the keyboard until the user clicks somewhere else.+ * dwell took it, leaving the node took it away. `settings.terminalFocusFollowsPointer` keeps the+ * hover dwell (the default) or switches to click-to-focus, where the pointer decides nothing and the+ * clicked terminal keeps the keyboard until the user clicks somewhere else.+ *+ * Since then the default became SLOPPY focus: the dwell still takes the keyboard, but leaving the+ * node no longer takes it away — it stays until another node takes it (a dwell, a click) or the+ * user clicks elsewhere. Typing into a terminal while the mouse rests on the canvas no longer+ * silently stops working.*/describe('terminal focus mode (#757)', () => {it('defaults to focus-follows-pointer, so nobody’s terminal changes behaviour on upgrade', () => {@@ -42,12 +49,42 @@ describe('terminal focus mode (#757)', () => {})})- describe('pointerLeaveReleases', () => {- it('takes the keyboard away on mouseleave only while focus follows the pointer', () => {- expect(pointerLeaveReleases(true)).toBe(true)- // Click-to-focus: the pointer wandering to another card, the canvas or a second display- // must leave the typed-into terminal exactly as it is.- expect(pointerLeaveReleases(false)).toBe(false)+ describe('pointerLeaveRearmsGuard', () => {+ it('re-arms the guard on mouseleave only while focus follows the pointer', () => {+ // The guard is a POINTER contract in that mode: a pass-over scroll pans the canvas until the+ // next dwell, so leaving must put it back.+ expect(pointerLeaveRearmsGuard(true)).toBe(true)+ // Click to focus: the guard follows DOM focus, and the pointer wandering off changes nothing.+ expect(pointerLeaveRearmsGuard(false)).toBe(false)+ })+ })++ describe('focusDrivesGuard', () => {+ it('lets focus changes arm and disarm the guard only in click to focus', () => {+ expect(focusDrivesGuard(false)).toBe(true)+ // Focus follows the pointer: the dwell, a click and mouseleave own the guard. A release that+ // re-armed it would strand a pointer resting on the body behind an armed guard with no+ // mouseenter coming to restart the dwell; a reclaim that dropped it would let a pass-over+ // scroll reach tmux.+ expect(focusDrivesGuard(true)).toBe(false)+ })+ })++ describe('dwellBlursForeignTerminal', () => {+ // Sloppy focus: the pointer leaving a terminal no longer takes its keyboard, so the dwell onto+ // the NEXT node is what moves it. A node whose ⌘M view covers its xterm cannot take it, and+ // without this the terminal the user came from would keep receiving keystrokes while another+ // node reads as the active one.+ it('takes the keyboard off another terminal when this node cannot take it itself', () => {+ expect(dwellBlursForeignTerminal({ covered: true, activeIsForeignXterm: true })).toBe(true)+ })++ it('leaves it to focus() when the xterm is not covered (focusing it moves the keyboard anyway)', () => {+ expect(dwellBlursForeignTerminal({ covered: false, activeIsForeignXterm: true })).toBe(false)+ })++ it('never blurs anything but another terminal (a sticky, an editor, a field keep their caret)', () => {+ expect(dwellBlursForeignTerminal({ covered: true, activeIsForeignXterm: false })).toBe(false)})})@@ -180,8 +217,17 @@ describe('terminal focus mode (#757)', () => {const src = read('src/renderer/nodes/TerminalNode.tsx')expect(src).toContain('useSettings((s) => s.settings.terminalFocusFollowsPointer)')expect(src).toContain('hoverTakesKeyboard(focusFollowsPointer)')- expect(src).toContain('pointerLeaveReleases(focusFollowsPointer)')- expect(src).toContain('useClickToFocus(!focusFollowsPointer,')+ expect(src).toContain('pointerLeaveRearmsGuard(focusFollowsPointer)')+ // Sloppy focus: DOM focus owns the keyboard in BOTH modes, so the hook always runs and only+ // the guard is mode-dependent.+ expect(src).toContain('useClickToFocus({')+ expect(src).toContain('if (focusDrivesGuard(focusFollowsPointer)) setArmed(armed)')+ expect(src).toContain('dwellBlursForeignTerminal({')+ // The pointer leaving never takes the keyboard away: no blur, no release, in either mode.+ const leave = src.slice(src.indexOf('const onBodyLeave = () => {'), src.indexOf('useClickToFocus({'))+ expect(leave).not.toContain('blur()')+ expect(leave).not.toContain('setActive(id, false)')+ expect(leave).not.toContain('releaseFocus(')// A dwell already running when the setting is switched off must not still take the keyboard:// the timer re-reads the LIVE setting, and switching off cancels a pending dwell.expect(src).toContain('if (!hoverTakesKeyboard(focusFollowsPointerRef.current)) return')diff --git a/src/renderer/lib/terminalFocusMode.ts b/src/renderer/lib/terminalFocusMode.tsindex bc732c9e4..438b4c59d 100644--- a/src/renderer/lib/terminalFocusMode.ts+++ b/src/renderer/lib/terminalFocusMode.ts@@ -10,14 +10,22 @@** `settings.terminalFocusFollowsPointer` (default ON — the long-standing behaviour) picks the model:*- * - **ON — focus follows the pointer.** Unchanged: hover dwell takes the keyboard, leaving the- * node gives it back.+ * - **ON — focus follows the pointer, sloppily.** A hover dwell takes the keyboard, and the+ * terminal KEEPS it after the pointer leaves — until another node takes it (its own dwell, a+ * click) or the user clicks elsewhere. This used to be strict X11 focus-follows-mouse, where+ * `mouseleave` blurred the xterm and dropped the active flag and presence focus: typing into a+ * terminal while the mouse rested on the canvas silently went nowhere, and so did every reach for+ * the sidebar mid-prompt. Only the hover GUARD still follows the pointer here (leaving re-arms+ * it, so a pass-over scroll pans the canvas until the next dwell).* - **OFF — click to focus.** The pointer decides nothing. A click on the terminal (the guard's* `onGuardClick` → `enterNow`, issue #87) or a "go to node" request takes the keyboard, and the* terminal KEEPS it until focus really goes somewhere else: another node, the empty canvas- * (whose `onPaneClick` blurs the xterm textarea, issue #86), a text field. The node's active- * flag, presence focus and hover guard then follow that DOM focus instead of the pointer — see- * `focusLossOutcome`.+ * (whose `onPaneClick` blurs the xterm textarea, issue #86), a text field. The guard follows+ * DOM focus too.+ *+ * In BOTH modes the node's active flag and presence focus follow DOM focus, through+ * `useClickToFocus` (named for #757, where it was born) — see `focusLossOutcome`. The modes differ+ * only in how the keyboard is TAKEN (dwell or click) and in who owns the guard.** Pure so the decisions are testable without a mounted xterm; `TerminalNode` owns the effects.*/@@ -37,13 +45,42 @@ export function hoverTakesKeyboard(focusFollowsPointer: boolean): boolean {}/**- * Does the pointer leaving the body take the keyboard away (blur the xterm, re-arm the guard,- * drop the active flag and presence focus)? Click-to-focus leaves all of that to `focusLossOutcome`.+ * Does the pointer leaving the body re-arm the hover guard? Only while focus follows the pointer,+ * where the guard is a pointer contract. It never takes the keyboard away, in either mode: the+ * keyboard, the active flag and presence focus are released by `focusLossOutcome`, which follows+ * where the KEYBOARD goes rather than where the mouse goes.*/-export function pointerLeaveReleases(focusFollowsPointer: boolean): boolean {+export function pointerLeaveRearmsGuard(focusFollowsPointer: boolean): boolean {return focusFollowsPointer}+/**+ * Do DOM focus changes arm and disarm the hover guard (`useClickToFocus`'s `setArmed`)?+ *+ * Only in click to focus, where the guard has no other owner. While focus follows the pointer the+ * dwell, a click and `mouseleave` own it, and focus moving would get it wrong both ways: a release+ * while the pointer rests on the body (⌘K, a sidebar jump) would re-arm it with no `mouseenter`+ * coming to restart the dwell, and a reclaim after a header drag would drop it while the pointer is+ * elsewhere, so the next pass-over scroll would reach tmux instead of panning the canvas.+ */+export function focusDrivesGuard(focusFollowsPointer: boolean): boolean {+ return !focusFollowsPointer+}++/**+ * Should a hover dwell that has just made this node active blur the element holding the keyboard?+ *+ * With sloppy focus the dwell onto the NEXT node is what moves the keyboard: focusing its xterm+ * takes it from the terminal the user came from. A node whose ⌘M view covers its xterm cannot take+ * it (`focusXtermUnlessCovered`), so the previous terminal would keep receiving keystrokes while+ * this node reads as the active one — typing into a pane nobody is looking at. Only ANOTHER+ * terminal's xterm is blurred: a sticky, an editor or a text field keeps its caret, exactly as it+ * did when `mouseleave` was what released a terminal.+ */+export function dwellBlursForeignTerminal(p: { covered: boolean; activeIsForeignXterm: boolean }): boolean {+ return p.covered && p.activeIsForeignXterm+}+/** The slice of a node's root element this module reads. */export interface NodeRootLike {contains(other: unknown): boolean@@ -69,7 +106,7 @@ export interface FocusLossEvent {lostIsCoveredXterm: boolean}-/** What a `focusout` inside the node means in click-to-focus mode. */+/** What a `focusout` inside the node means (both modes since sloppy focus). */export type FocusLossOutcome =/** Nothing changed that the node must act on. */| 'keep'@@ -79,7 +116,7 @@ export type FocusLossOutcome =| 'release'/**- * Click to focus: what did a `focusout` inside this node mean?+ * What did a `focusout` inside this node mean? (Born for click to focus; both modes use it now.)** The one place the node's "I hold the keyboard" state is released in that mode, so it must tell* a real move from its look-alikes:@@ -123,14 +160,15 @@ export interface OutsidePress {}/**- * Click to focus: does a press ANYWHERE ELSE release a node that holds no DOM focus?+ * Does a press ANYWHERE ELSE release a node that holds no DOM focus? (Both modes.)** `focusLossOutcome` can only answer for a node that had focus to lose. Activity is also claimed* without it: a "go to node" while the ⌘M view covers the xterm (`enterNow` reports activity, but* `focusXtermUnlessCovered` deliberately leaves the hidden terminal unfocused) and Canvas's own- * `setActive` on a sidebar or notification jump. With focus-follows-pointer, `mouseleave` cleaned- * that up; with click to focus nothing did, and a stale active flag makes Canvas treat the node as- * watched — its next finish never gets an unread dot — and leaves presence saying "working here".+ * `setActive` on a sidebar or notification jump. Strict focus-follows-pointer had `mouseleave`+ * clean that up; with click to focus, and now sloppy focus, nothing else does, and a stale active+ * flag makes Canvas treat the node as watched — its next finish never gets an unread dot — and+ * leaves presence saying "working here".** So a press outside such a node is the user clicking elsewhere, which is the release #757 names.* A node that DOES hold focus is left to its own `focusout` (the press may not move focus at all —@@ -141,7 +179,7 @@ export function outsidePressReleases(p: OutsidePress): boolean {}/**- * Click to focus, `reclaim`: which element gets the keyboard back after a press on the node's own+ * `reclaim`: which element gets the keyboard back after a press on the node's own* chrome? The one that lost it, when it is still inside the node and is not the xterm (the ⌘M* composer — the covered xterm cannot take focus, so falling back to it strands the keyboard on the* React Flow wrapper); otherwise the xterm, through `focusXtermUnlessCovered`.@@ -151,10 +189,11 @@ export function reclaimTarget(p: { lostIsXterm: boolean; lostStillInNode: boolea}/**- * Click to focus: does this press ACKNOWLEDGE the node (the `enterNow` routine — active flag,- * `clearUnread`, presence, remember, and the xterm focused unless the ⌘M view covers it)?+ * Does this press ACKNOWLEDGE the node (the `enterNow` routine — active flag, `clearUnread`,+ * presence, remember, and the xterm focused unless the ⌘M view covers it)?*- * Focus-follows-pointer acknowledges on every dwell. Click to focus has no dwell, so a deliberate+ * Focus-follows-pointer acknowledges on every dwell, and a body press there is a dwell's worth of+ * intent anyway (the guard is already down). Click to focus has no dwell, so a deliberate* primary press anywhere in the node BODY is the acknowledgement: on the xterm even when the guard is* already down (Codex round 3 — a finish that turned unread while the window was inactive could not* be cleared by clicking the terminal it belongs to), on the open ⌘M view, on its composer. Threediff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsxindex 82366c54b..7a49858f8 100644--- a/src/renderer/nodes/TerminalNode.tsx+++ b/src/renderer/nodes/TerminalNode.tsx@@ -238,10 +238,13 @@ import { ContextMeter } from '../components/ContextMeter'import { isZoomModifierHeld } from '../lib/zoomModifier'import { HoverGuard } from './HoverGuard'import {+ dwellBlursForeignTerminal,+ focusDrivesGuard,hoverTakesKeyboard,- pointerLeaveReleases,+ pointerLeaveRearmsGuard,resolveFocusFollowsPointer} from '../lib/terminalFocusMode'+import { XTERM_INPUT_CLASS } from '../lib/keyContext'import { useClickToFocus } from './useClickToFocus'import { reparentKeepingFocus } from './reparentKeepingFocus'import { isHidden } from '../lib/ui-visibility'@@ -5617,6 +5620,18 @@ export function TerminalNode({return}setArmed(false)+ // Sloppy focus: this dwell, not the pointer leaving, takes the keyboard off the terminal the+ // user came from — even when the ⌘M view leaves nothing here that could take it.+ const held = document.activeElement+ if (+ held instanceof HTMLElement &&+ dwellBlursForeignTerminal({+ covered: mdModeRef.current,+ activeIsForeignXterm: held.classList.contains(XTERM_INPUT_CLASS) && !rootRef.current?.contains(held)+ })+ ) {+ held.blur()+ }focusXtermUnlessCovered(termRef.current, mdModeRef.current)useTerminalFocus.getState().remember(id)useAgentStatus.getState().setActive(id, true)@@ -5630,21 +5645,21 @@ export function TerminalNode({}const onBodyLeave = () => {if (dwellRef.current) clearTimeout(dwellRef.current)- // Click to focus (#757): the pointer wandering off — to another card, the sidebar, a second- // display — leaves the terminal exactly as it is. It keeps the keyboard, the guard stays down- // and the node stays active; all of that is released by the focus-loss listener below, which- // follows where the KEYBOARD goes rather than where the mouse goes.- if (!pointerLeaveReleases(focusFollowsPointer)) return- setArmed(true)- termRef.current?.blur()- useAgentStatus.getState().setActive(id, false)- presence.releaseFocus(id)+ // The pointer wandering off — to the canvas, another card, the sidebar, a second display —+ // never takes the keyboard away, in either mode: the terminal keeps it and the node stays+ // active until another node takes it or the user clicks elsewhere (sloppy focus). That release+ // is the focus-loss listener's below, which follows where the KEYBOARD goes rather than where+ // the mouse goes. Strict focus-follows-pointer used to blur here, so typing with the mouse+ // resting off the node silently went nowhere. Only the guard still follows the pointer while+ // focus follows it: a pass-over scroll must pan the canvas until the next dwell.+ if (pointerLeaveRearmsGuard(focusFollowsPointer)) setArmed(true)}- // Click to focus (#757): who holds the keyboard follows DOM focus and deliberate presses, not the- // pointer — the whole mechanism, its measurements and its refusals live in `useClickToFocus`.- // Every callback is read live from this render; the listeners are bound once per mode switch, to- // the node root, which is the one element that survives focus mode's reparent.- useClickToFocus(!focusFollowsPointer, {+ // Who holds the keyboard follows DOM focus and deliberate presses, not the pointer, in BOTH modes+ // — the whole mechanism, its measurements and its refusals live in `useClickToFocus` (#757). The+ // modes differ in who owns the guard: focus here only in click to focus, the pointer otherwise.+ // Every callback is read live from this render; the listeners are bound once, to the node root,+ // which is the one element that survives focus mode's reparent.+ useClickToFocus({id,root: () => rootRef.current,xtermTextarea: () => termRef.current?.textarea,@@ -5652,7 +5667,9 @@ export function TerminalNode({reparenting: () => reparentingRef.current,acknowledge: () => enterNow(),focusXterm: () => focusXtermUnlessCovered(termRef.current, mdModeRef.current),- setArmed,+ setArmed: (armed) => {+ if (focusDrivesGuard(focusFollowsPointer)) setArmed(armed)+ },remember: () => useTerminalFocus.getState().remember(id),isActive: () => useAgentStatus.getState().activeId === id,setActive: (active) => useAgentStatus.getState().setActive(id, active),diff --git a/src/renderer/nodes/useClickToFocus.test.tsx b/src/renderer/nodes/useClickToFocus.test.tsxindex cd30e1ebe..302abcd6e 100644--- a/src/renderer/nodes/useClickToFocus.test.tsx+++ b/src/renderer/nodes/useClickToFocus.test.tsx@@ -7,7 +7,8 @@ import { useClickToFocus, type ClickToFocusHost } from './useClickToFocus';(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true/**- * Click-to-focus ownership (#757) against a real DOM shaped like a terminal node:+ * Keyboard ownership (#757 click to focus, and sloppy focus-follows-pointer) against a real DOM+ * shaped like a terminal node:** .react-flow__node (tabindex 0)* .term-node ← the stable root; focus mode MOVES this element@@ -91,12 +92,12 @@ describe('useClickToFocus', () => {reportFocus: vi.fn(() => calls.push('report')),releaseFocus: vi.fn(() => calls.push('release'))}- function Probe({ enabled }: { enabled: boolean }) {- useClickToFocus(enabled, host)+ function Probe() {+ useClickToFocus(host)return null}reactRoot = createRoot(container)- act(() => reactRoot.render(<Probe enabled />))+ act(() => reactRoot.render(<Probe />))})afterEach(() => {@@ -236,23 +237,24 @@ describe('useClickToFocus', () => {expect(calls).not.toContain('release')})- it('does nothing while focus follows the pointer', () => {- act(() =>- reactRoot.render(- (() => {- function Off() {- useClickToFocus(false, host)- return null- }- return <Off />- })()- )- )- guard.remove()- press(xterm)- host.active = true- press(outside)- expect(host.acknowledge).not.toHaveBeenCalled()- expect(calls).not.toContain('release')+ it('keeps a terminal the pointer has left until the keyboard really goes elsewhere (sloppy focus)', () => {+ // A hover dwell took the keyboard (the dwell is TerminalNode's; here it is the focus it causes).+ act(() => xterm.focus())+ expect(host.active).toBe(true)+ calls.length = 0+ // The pointer wanders off to the canvas: nothing about the keyboard may change.+ act(() => {+ body.dispatchEvent(new MouseEvent('mouseout', { bubbles: true, relatedTarget: outside }))+ outside.dispatchEvent(new MouseEvent('mouseover', { bubbles: true, relatedTarget: body }))+ })+ expect(document.activeElement).toBe(xterm)+ expect(host.active).toBe(true)+ expect(calls).toEqual([])+ // Another terminal's dwell focuses ITS xterm: that, not the pointer leaving, releases this one.+ const otherXterm = document.createElement('textarea')+ outside.append(otherXterm)+ act(() => otherXterm.focus())+ expect(calls).toContain('release')+ expect(calls).toContain('active:false')})})diff --git a/src/renderer/nodes/useClickToFocus.ts b/src/renderer/nodes/useClickToFocus.tsindex 8a20e5cf3..39efc8f56 100644--- a/src/renderer/nodes/useClickToFocus.ts+++ b/src/renderer/nodes/useClickToFocus.ts@@ -30,8 +30,11 @@ export interface ClickToFocusHost {}/**- * Click to focus (#757): the node's "I hold the keyboard" state follows DOM focus and deliberate- * presses, never the pointer's position.+ * The node's "I hold the keyboard" state follows DOM focus and deliberate presses, never the+ * pointer's position. Born for click to focus (#757); since sloppy focus it runs in BOTH modes — a+ * hover dwell only TAKES the keyboard, and losing it is this hook's job either way. In+ * focus-follows-pointer mode the host's `setArmed` is a no-op (`focusDrivesGuard`): the guard+ * belongs to the pointer there.** ONE document capture `pointerdown` listener plus `focusin`/`focusout` on the node root. Earlier* versions also listened on the React Flow wrapper, captured once when the effect ran — and focus@@ -50,11 +53,10 @@ export interface ClickToFocusHost {* Capture phase on the document, so React Flow's d3-drag (which stops mousedown at the wrapper) can* never hide a press. The focus decisions are the pure functions in `lib/terminalFocusMode.ts`.*/-export function useClickToFocus(enabled: boolean, host: ClickToFocusHost): void {+export function useClickToFocus(host: ClickToFocusHost): void {const hostRef = useRef(host)hostRef.current = hostuseEffect(() => {- if (!enabled) returnconst h = () => hostRef.currentconst root = h().root()if (!root) return@@ -177,5 +179,5 @@ export function useClickToFocus(enabled: boolean, host: ClickToFocusHost): voidroot.removeEventListener('focusin', onFocusIn)root.removeEventListener('focusout', onFocusOut)}- }, [enabled])+ }, [])}