Skip to content

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.

fix(canvas): reachable guard click and focusless release for click-to-focus (#757)

Erik Zwepde9b6b239998
diff --git a/CLAUDE.md b/CLAUDE.md
index f35b3a026..1c8f271a9 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -1263,13 +1263,19 @@ session.
the 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 (`onGuardUp` → `enterNow`) or a "go to node" takes the
+ 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 through a
`focusin`/`focusout` listener on the node root (`lib/terminalFocusMode.ts` `focusLossOutcome`):
focus moving inside the node or the WINDOW blurring (Cmd+Tab) keeps it, a press on the node's own
chrome (header drag — React Flow focuses its wrapper) hands it back to the xterm, anything else —
another node, a field, the empty canvas (`onPaneClick` blurs the xterm textarea,
- `shouldReleasePaneFocus`) — releases it and re-arms the guard. Only a literal `false` in
+ `shouldReleasePaneFocus`) — releases it and re-arms the guard. Activity claimed WITHOUT focus
+ (go-to-node under the ⌘M view, Canvas's own `setActive` on a jump) has no focusout, so a
+ document capture `pointerdown` outside the node releases it (`outsidePressReleases`) — else the
+ stale `activeId` suppresses that node's unread dot. The guard listens to POINTER events
+ (`nodes/HoverGuard.tsx`): React Flow's d3-drag swallows a left `mousedown`/`mouseup` on a
+ draggable node before React sees them, so the old mouse-event guard never received a left click
+ (#87's click-to-focus only ever worked through the dwell). Only a literal `false` in
settings.json selects it (`resolveFocusFollowsPointer`). The ⌘/ shortcuts panel prints "Click" instead of
the dwell. Renderer only: Desktop + Server Edition identical; kanban card modal N/A (it has no
hover guard); Mobile N/A.
diff --git a/src/renderer/lib/terminalFocusMode.test.ts b/src/renderer/lib/terminalFocusMode.test.ts
index 3959b48fa..c095abba1 100644
--- a/src/renderer/lib/terminalFocusMode.test.ts
+++ b/src/renderer/lib/terminalFocusMode.test.ts
@@ -4,6 +4,7 @@ import { join } from 'path'
import { DEFAULT_SETTINGS } from '@shared/types'
import {
focusLossOutcome,
+ outsidePressReleases,
hoverTakesKeyboard,
pointerLeaveReleases,
resolveFocusFollowsPointer
@@ -103,6 +104,29 @@ describe('terminal focus mode (#757)', () => {
})
})
+ describe('outsidePressReleases', () => {
+ // Activity can be claimed without this node ever holding DOM focus: "go to node" while the ⌘M
+ // view covers the xterm (`focusXtermUnlessCovered` deliberately does not focus it), and Canvas's
+ // own `setActive` on a sidebar / notification jump. No `focusout` can come from a node that has
+ // no focus, and with click to focus `mouseleave` no longer releases either — so a stale active
+ // flag suppressed the unread dot for that node until something else became active.
+ it('releases a node that claims activity but holds no focus when the user presses elsewhere', () => {
+ expect(outsidePressReleases({ isActive: true, pressInsideNode: false, focusInsideNode: false })).toBe(true)
+ })
+
+ it('leaves a node alone whose focus will report its own loss (the focusout path owns that)', () => {
+ expect(outsidePressReleases({ isActive: true, pressInsideNode: false, focusInsideNode: true })).toBe(false)
+ })
+
+ it('never releases on a press inside the node itself', () => {
+ expect(outsidePressReleases({ isActive: true, pressInsideNode: true, focusInsideNode: false })).toBe(false)
+ })
+
+ it('has nothing to release when the node is not the active one', () => {
+ expect(outsidePressReleases({ isActive: false, pressInsideNode: false, focusInsideNode: false })).toBe(false)
+ })
+ })
+
// The decisions above are only worth something if the node and the settings page use them. A
// source check, like `focusRestore.test.ts`: TerminalNode cannot be mounted without an xterm.
describe('wiring', () => {
@@ -114,6 +138,7 @@ describe('terminal focus mode (#757)', () => {
expect(src).toContain('hoverTakesKeyboard(focusFollowsPointer)')
expect(src).toContain('pointerLeaveReleases(focusFollowsPointer)')
expect(src).toContain('focusLossOutcome(')
+ expect(src).toContain('outsidePressReleases(')
})
it('Settings → Behavior offers the toggle, findable by search', () => {
diff --git a/src/renderer/lib/terminalFocusMode.ts b/src/renderer/lib/terminalFocusMode.ts
index 13c0747bd..c71d7ced0 100644
--- a/src/renderer/lib/terminalFocusMode.ts
+++ b/src/renderer/lib/terminalFocusMode.ts
@@ -13,7 +13,7 @@
* - **ON — focus follows the pointer.** Unchanged: hover dwell takes the keyboard, leaving the
* node gives it back.
* - **OFF — click to focus.** The pointer decides nothing. A click on the terminal (the guard's
- * `onGuardUp` → `enterNow`, issue #87) or a "go to node" request takes the keyboard, and the
+ * `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
@@ -103,3 +103,30 @@ export function focusLossOutcome(e: FocusLossEvent): FocusLossOutcome {
if (e.pressedInOwnNode) return 'reclaim'
return 'release'
}
+
+export interface OutsidePress {
+ /** This node is the agent-status `activeId` (the one whose finishes are "being watched"). */
+ isActive: boolean
+ /** The press landed on this node (its React Flow wrapper, header included). */
+ pressInsideNode: boolean
+ /** `document.activeElement` is inside this node's root at the time of the press. */
+ focusInsideNode: boolean
+}
+
+/**
+ * Click to focus: does a press ANYWHERE ELSE release a node that holds no DOM focus?
+ *
+ * `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".
+ *
+ * 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 —
+ * a pane drag, a scroll — and then it rightly keeps the keyboard).
+ */
+export function outsidePressReleases(p: OutsidePress): boolean {
+ return p.isActive && !p.pressInsideNode && !p.focusInsideNode
+}
diff --git a/src/renderer/nodes/HoverGuard.test.tsx b/src/renderer/nodes/HoverGuard.test.tsx
new file mode 100644
index 000000000..61d76b553
--- /dev/null
+++ b/src/renderer/nodes/HoverGuard.test.tsx
@@ -0,0 +1,140 @@
+// @vitest-environment jsdom
+import { act } from 'react'
+import { createRoot, type Root } from 'react-dom/client'
+import { drag } from 'd3-drag'
+import { select } from 'd3-selection'
+import { readFileSync } from 'node:fs'
+import { resolve } from 'node:path'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { GUARD_CLICK_SLOP, HoverGuard } from './HoverGuard'
+
+;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true
+
+/**
+ * The hover guard sits inside a React Flow node wrapper that carries a REAL d3-drag instance: a
+ * terminal node has no `dragHandle` and the guard is not `.nodrag`, so React Flow's drag filter
+ * (@xyflow/system `XYDrag`: `!event.button && !hasSelector(target, '.nodrag')`) accepts a left press
+ * on it. d3-drag's `mousedowned` then calls `stopImmediatePropagation` on the WRAPPER, so the
+ * mousedown never bubbles to React's root listener, and it consumes the `mouseup` with a
+ * `stopImmediatePropagation` in a WINDOW capture listener, so React never sees that either. A guard
+ * built on `onMouseDown`/`onMouseUp` therefore never ran for a left click — issue #87's
+ * click-to-focus was dead, masked by the hover dwell (and with click to focus, #757, there is no
+ * dwell to mask it).
+ *
+ * These tests mount the guard under the real d3-drag with React Flow's filter, and dispatch the
+ * sequence a browser produces, so the event path is the production one rather than a simulation of
+ * the handler.
+ */
+describe('HoverGuard under React Flow’s d3-drag (#87, #757)', () => {
+ let container: HTMLDivElement
+ let root: Root
+ let wrapper: HTMLDivElement
+
+ beforeEach(() => {
+ container = document.createElement('div')
+ document.body.appendChild(container)
+ root = createRoot(container)
+ })
+
+ afterEach(() => {
+ act(() => root.unmount())
+ container.remove()
+ })
+
+ /** Render `children` inside a wrapper with React Flow's drag behaviour on it. */
+ function mount(children: React.ReactNode): void {
+ act(() => {
+ root.render(
+ <div
+ className="react-flow__node"
+ ref={(el) => {
+ if (el) wrapper = el
+ }}
+ >
+ {children}
+ </div>
+ )
+ })
+ const filter = (event: MouseEvent) =>
+ !event.button && !(event.target as Element).closest('.nodrag')
+ select(wrapper).call(drag<HTMLDivElement, unknown>().filter(filter))
+ }
+
+ /** What a browser dispatches for a press and release of the given button at two points. */
+ function press(target: Element, from: [number, number], to: [number, number], button = 0): void {
+ const init = (type: string, [x, y]: [number, number]) => {
+ const ev = new MouseEvent(type, { bubbles: true, cancelable: true, clientX: x, clientY: y, button })
+ // d3-drag hangs its move/up listeners off `event.view`. jsdom's constructor refuses the test
+ // global as a `view` under this setup, so it is attached after construction instead.
+ Object.defineProperty(ev, 'view', { value: window })
+ return ev
+ }
+ act(() => {
+ target.dispatchEvent(init('pointerdown', from))
+ target.dispatchEvent(init('mousedown', from))
+ if (from[0] !== to[0] || from[1] !== to[1]) {
+ target.dispatchEvent(init('pointermove', to))
+ target.dispatchEvent(init('mousemove', to))
+ }
+ target.dispatchEvent(init('pointerup', to))
+ target.dispatchEvent(init('mouseup', to))
+ target.dispatchEvent(init('click', to))
+ })
+ }
+
+ it('is the premise: React never sees a left mousedown/mouseup inside a draggable node', () => {
+ const onMouseDown = vi.fn()
+ const onMouseUp = vi.fn()
+ mount(<div className="probe" onMouseDown={onMouseDown} onMouseUp={onMouseUp} />)
+ press(wrapper.querySelector('.probe')!, [10, 10], [10, 10])
+ expect(onMouseDown).not.toHaveBeenCalled()
+ expect(onMouseUp).not.toHaveBeenCalled()
+ })
+
+ it('a click on the guard reaches onClick', () => {
+ const onPress = vi.fn()
+ const onClick = vi.fn()
+ const onDragEnd = vi.fn()
+ mount(<HoverGuard onPress={onPress} onClick={onClick} onDragEnd={onDragEnd} />)
+ press(wrapper.querySelector('.term-hover-guard')!, [10, 10], [10, 10])
+ expect(onPress).toHaveBeenCalledTimes(1)
+ expect(onClick).toHaveBeenCalledTimes(1)
+ expect(onDragEnd).not.toHaveBeenCalled()
+ })
+
+ it('a few pixels of hand travel is still a click', () => {
+ const onClick = vi.fn()
+ const onDragEnd = vi.fn()
+ mount(<HoverGuard onPress={vi.fn()} onClick={onClick} onDragEnd={onDragEnd} />)
+ press(wrapper.querySelector('.term-hover-guard')!, [10, 10], [10 + GUARD_CLICK_SLOP, 10])
+ expect(onClick).toHaveBeenCalledTimes(1)
+ expect(onDragEnd).not.toHaveBeenCalled()
+ })
+
+ it('a drag that moved the node is not a click', () => {
+ const onClick = vi.fn()
+ const onDragEnd = vi.fn()
+ mount(<HoverGuard onPress={vi.fn()} onClick={onClick} onDragEnd={onDragEnd} />)
+ press(wrapper.querySelector('.term-hover-guard')!, [10, 10], [40, 40])
+ expect(onClick).not.toHaveBeenCalled()
+ expect(onDragEnd).toHaveBeenCalledTimes(1)
+ })
+
+ it('a right click (the context menu) does not take the keyboard', () => {
+ const onClick = vi.fn()
+ const onPress = vi.fn()
+ mount(<HoverGuard onPress={onPress} onClick={onClick} onDragEnd={vi.fn()} />)
+ press(wrapper.querySelector('.term-hover-guard')!, [10, 10], [10, 10], 2)
+ expect(onPress).not.toHaveBeenCalled()
+ expect(onClick).not.toHaveBeenCalled()
+ })
+
+ it('is the guard TerminalNode actually renders (no mouse-event guard left behind)', () => {
+ // Source pin: TerminalNode is a 6000-line component that cannot be mounted here, and a bare
+ // `<div className="term-hover-guard" onMouseDown=…>` reintroduced there would compile, pass every
+ // other test, and silently bring the dead click back.
+ const src = readFileSync(resolve(__dirname, 'TerminalNode.tsx'), 'utf8').replace(/\r\n/g, '\n')
+ expect(src).toContain('<HoverGuard onPress={onGuardPress} onClick={onGuardClick} onDragEnd={onBodyEnter} />')
+ expect(src).not.toMatch(/className="term-hover-guard"/)
+ })
+})
diff --git a/src/renderer/nodes/HoverGuard.tsx b/src/renderer/nodes/HoverGuard.tsx
new file mode 100644
index 000000000..7c0eef767
--- /dev/null
+++ b/src/renderer/nodes/HoverGuard.tsx
@@ -0,0 +1,68 @@
+import { useRef } from 'react'
+import type { PointerEvent as ReactPointerEvent } from 'react'
+
+/**
+ * How far the pointer may travel between press and release and still count as a CLICK on the hover
+ * guard, in screen px. Above it the gesture moved the node and the terminal keeps waiting; below
+ * it, the click focuses immediately (issue #87).
+ *
+ * Generous rather than tight: a few pixels of travel is a hand, not an intent, and the cost of
+ * being wrong is asymmetric — a missed focus makes the user click again (and, before this, made
+ * that click count against them), while an over-eager focus costs one Escape.
+ */
+export const GUARD_CLICK_SLOP = 4
+
+export interface HoverGuardProps {
+ /** A primary press landed on the guard (it may still become a drag). */
+ onPress: () => void
+ /** The press was released within `GUARD_CLICK_SLOP` of where it started: a click. */
+ onClick: () => void
+ /** The press was released after the node moved (or its start was never seen): a drag. */
+ onDragEnd: () => void
+}
+
+/**
+ * The transparent overlay over a terminal body that makes a quick drag move the node and a wheel
+ * pan the canvas until the terminal takes the keyboard (see TerminalNode's hover dwell / #757).
+ *
+ * **It listens to POINTER events, and that is the whole point of this component.** The guard sits
+ * inside a React Flow node wrapper carrying a d3-drag instance: a terminal node has no `dragHandle`
+ * and the guard is not `.nodrag`, so React Flow's drag filter accepts a left press on it. d3-drag
+ * then calls `stopImmediatePropagation` on the `mousedown` AT THE WRAPPER — so it never bubbles to
+ * React's root listener — and consumes the `mouseup` with `stopImmediatePropagation` in a WINDOW
+ * capture listener, which runs before React's root sees it at all (d3-drag 3.0.0 `mousedowned` /
+ * `mouseupped`). The guard used `onMouseDown`/`onMouseUp` until this was measured: the #87 "a click
+ * focuses at once" path never ran for a left click, masked by the hover dwell, and with click to
+ * focus (#757) there was no dwell left to mask it. d3-drag does not touch pointer events, which
+ * fire before the mouse events and bubble normally, so the drag layer still moves the node and the
+ * guard still sees both halves of the gesture. `HoverGuard.test.tsx` pins this under the real
+ * d3-drag with React Flow's filter.
+ *
+ * Only the PRIMARY button counts: a right click opens the context menu and must not take the
+ * keyboard (with mouse events it did, because React Flow's filter lets a right press through
+ * untouched — the one click that ever reached the old handlers).
+ */
+export function HoverGuard({ onPress, onClick, onDragEnd }: HoverGuardProps) {
+ const downAt = useRef<{ x: number; y: number } | null>(null)
+ const onPointerDown = (e: ReactPointerEvent<HTMLDivElement>) => {
+ if (e.button !== 0) return
+ downAt.current = { x: e.clientX, y: e.clientY }
+ onPress()
+ }
+ const onPointerUp = (e: ReactPointerEvent<HTMLDivElement>) => {
+ if (e.button !== 0) return
+ const from = downAt.current
+ downAt.current = null
+ const moved = from ? Math.hypot(e.clientX - from.x, e.clientY - from.y) : Infinity
+ if (from && moved <= GUARD_CLICK_SLOP) onClick()
+ else onDragEnd()
+ }
+ return (
+ <div
+ className="term-hover-guard"
+ onPointerDown={onPointerDown}
+ onPointerUp={onPointerUp}
+ title="Click to type · drag to move · scroll to pan"
+ />
+ )
+}
diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsx
index 709fc8b2a..87a6bc0df 100644
--- a/src/renderer/nodes/TerminalNode.tsx
+++ b/src/renderer/nodes/TerminalNode.tsx
@@ -208,9 +208,11 @@ import { useTerminalSearch } from '../terminal/useTerminalSearch'
import { useCopyFeedback } from '../terminal/useCopyFeedback'
import { ContextMeter } from '../components/ContextMeter'
import { isZoomModifierHeld } from '../lib/zoomModifier'
+import { HoverGuard } from './HoverGuard'
import {
focusLossOutcome,
hoverTakesKeyboard,
+ outsidePressReleases,
pointerLeaveReleases,
resolveFocusFollowsPointer
} from '../lib/terminalFocusMode'
@@ -884,16 +886,8 @@ const CELL_SIZE_EPS = 0.01
* can only make that respawn fresh, not impossible — it would resurrect a terminal its owner
* deliberately killed. Cleared only on permanent deletion (disposeTerminalOnUnmount).
*/
-/**
- * How far the pointer may travel between press and release and still count as a CLICK on the hover
- * guard, in screen px. Above it the gesture moved the node and the terminal keeps waiting; below
- * it, the click focuses immediately (issue #87).
- *
- * Generous rather than tight: a few pixels of travel is a hand, not an intent, and the cost of
- * being wrong is asymmetric — a missed focus makes the user click again (and, before this, made
- * that click count against them), while an over-eager focus costs one Escape.
- */
-const GUARD_CLICK_SLOP = 4
+// GUARD_CLICK_SLOP (the click-vs-drag threshold on the hover guard) lives with the guard itself,
+// in `HoverGuard.tsx`, beside the pointer-event handling that makes the click reachable at all.
interface CoState {
/** The pty runs at a SMALLER subscriber's grid than we could fit → center + letterbox. */
@@ -1340,8 +1334,6 @@ export function TerminalNode({
// button are absent from `isHidden`'s inventory and stay put whatever the list says.
const hiddenHeaderButtons = useSettings((s) => s.settings.hiddenHeaderButtons)
const bodyRef = useRef<HTMLDivElement>(null)
- /** Where a press on the hover guard started, for the click-vs-drag test in `onGuardUp`. */
- const guardDownAt = useRef<{ x: number; y: number } | null>(null)
const middleClickPaste = useSettings((st) => st.settings.terminalMiddleClickPaste)
// Chromium pastes the X PRIMARY selection into xterm's hidden textarea on middle click — a path
// this app never built and the user could not switch off (issue #84). Its own effect, keyed on
@@ -5198,7 +5190,7 @@ export function TerminalNode({
/**
* Take the keyboard: focus xterm, leave the guard, and report the node active.
*
- * Split out of `onBodyEnter` so a deliberate CLICK can run it with no delay — see `onGuardUp`.
+ * Split out of `onBodyEnter` so a deliberate CLICK can run it with no delay — see `onGuardClick`.
*
* `ack` (default true) says a human AIMED at this node, and two things follow from it. It marks
* the node's finish read, which reaches past this machine (`clearUnread` → `ackDone` → the notch
@@ -5244,7 +5236,7 @@ export function TerminalNode({
const onBodyEnter = () => {
if (dwellRef.current) clearTimeout(dwellRef.current)
// Click to focus (#757): hovering never takes the keyboard. A click still does, at once, through
- // the guard (`onGuardUp` → `enterNow`); a drag that started on the guard comes back here and,
+ // the guard (`onGuardClick` → `enterNow`); a drag that started on the guard comes back here and,
// correctly, arms nothing.
if (!hoverTakesKeyboard(focusFollowsPointer)) return
const enter = () => {
@@ -5362,22 +5354,35 @@ export function TerminalNode({
if (!ta || document.activeElement !== ta) release()
}, 0)
}
+ // Activity claimed WITHOUT focus (a go-to-node under the ⌘M view, Canvas's own setActive on a
+ // jump) has no focusout to end it; a press anywhere else does (`outsidePressReleases`). Capture
+ // phase, so React Flow's d3 handlers cannot hide the press, and a cheap `activeId` check first:
+ // every mounted terminal carries one of these.
+ const onDocPointerDown = (e: PointerEvent) => {
+ const releases = outsidePressReleases({
+ isActive: useAgentStatus.getState().activeId === id,
+ pressInsideNode: e.target instanceof Node && wrapper.contains(e.target),
+ focusInsideNode: root.contains(document.activeElement)
+ })
+ if (releases) release()
+ }
+ document.addEventListener('pointerdown', onDocPointerDown, true)
wrapper.addEventListener('pointerdown', onPointerDown, true)
root.addEventListener('focusin', onFocusIn)
root.addEventListener('focusout', onFocusOut)
return () => {
if (pressTimer) clearTimeout(pressTimer)
if (reclaimTimer) clearTimeout(reclaimTimer)
+ document.removeEventListener('pointerdown', onDocPointerDown, true)
wrapper.removeEventListener('pointerdown', onPointerDown, true)
root.removeEventListener('focusin', onFocusIn)
root.removeEventListener('focusout', onFocusOut)
}
}, [focusFollowsPointer, id, presence])
- // While armed, a mousedown might start a node drag — pause the dwell timer so the
- // terminal doesn't grab focus mid-drag; the release decides what happens next (`onGuardUp`).
- const onGuardDown = (e: React.MouseEvent) => {
+ // While armed, a press might start a node drag — pause the dwell timer so the terminal doesn't
+ // grab focus mid-drag; the release decides what happens next (`onGuardClick` / `onBodyEnter`).
+ const onGuardPress = () => {
if (dwellRef.current) clearTimeout(dwellRef.current)
- guardDownAt.current = { x: e.clientX, y: e.clientY }
}
/**
* A release on the guard: focus NOW if it was a click, restart the dwell if it was a drag.
@@ -5392,16 +5397,19 @@ export function TerminalNode({
* start on one), which is why hovering has to wait. A click that did not move the node is not
* ambiguous at all, so it does not wait.
*
- * The threshold is what separates the two, and it is generous on purpose: a few pixels of travel
- * between press and release is a hand, not an intent to drag. Past it the node HAS moved, and
- * focusing a terminal the user just repositioned would be the old bug in the other direction.
+ * The threshold is what separates the two (`GUARD_CLICK_SLOP`, applied by `HoverGuard`), and it
+ * is generous on purpose: a few pixels of travel between press and release is a hand, not an
+ * intent to drag. Past it the node HAS moved, and focusing a terminal the user just repositioned
+ * would be the old bug in the other direction — a drag lands in `onBodyEnter` instead.
+ *
+ * For years this never ran for a left click at all: the guard listened to mouse events, which
+ * React Flow's d3-drag swallows before React sees them, so only the dwell ever focused. With
+ * click to focus (#757) there is no dwell, which is how it surfaced. `HoverGuard` explains the
+ * event path.
*/
- const onGuardUp = (e: React.MouseEvent) => {
- const from = guardDownAt.current
- guardDownAt.current = null
- const moved = from ? Math.hypot(e.clientX - from.x, e.clientY - from.y) : Infinity
- if (from && moved <= GUARD_CLICK_SLOP && !isZoomModifierHeld()) enterNow()
- else onBodyEnter()
+ const onGuardClick = () => {
+ if (isZoomModifierHeld()) onBodyEnter()
+ else enterNow()
}
// ---- file drop: paste dropped file paths into the terminal (native-terminal behavior) ----
@@ -6426,12 +6434,7 @@ export function TerminalNode({
</div>
)}
{armed && !mdMode && (
- <div
- className="term-hover-guard"
- onMouseDown={onGuardDown}
- onMouseUp={onGuardUp}
- title="Click to type · drag to move · scroll to pan"
- />
+ <HoverGuard onPress={onGuardPress} onClick={onGuardClick} onDragEnd={onBodyEnter} />
)}
{mdMode &&
(useChat ? (
diff --git a/src/renderer/terminal/copy-feedback.ts b/src/renderer/terminal/copy-feedback.ts
index 5d361700c..a103da0f0 100644
--- a/src/renderer/terminal/copy-feedback.ts
+++ b/src/renderer/terminal/copy-feedback.ts
@@ -12,7 +12,7 @@
/** What the header pill is showing. */
export type CopyFeedback = { kind: 'copied' | 'hint'; label: string } | null
-/** A click is not a drag. Same intent as `GUARD_CLICK_SLOP` in TerminalNode: a few pixels of
+/** A click is not a drag. Same intent as `GUARD_CLICK_SLOP` in nodes/HoverGuard.tsx: a few pixels of
* travel between press and release is a hand, not an intent — and a plain click inside a
* mouse-capturing pane is the single most common interaction there, so it must stay silent. */
export const DRAG_MIN_PX = 8