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): clicking a terminal focuses it, and clicking the pane releases the keyboard (#86, #87)
enes32217d600390
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex 274b67245..1608c30b0 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -109,6 +109,7 @@ import { CloneRepoDialog } from '../components/CloneRepoDialog'import { markMobileLaunchSeen, shouldShowMobileLaunch } from '../lib/mobileLaunch'import type { DictationTarget } from '../components/DictationOverlay'import { describeOs, REPO_URL } from '../lib/bugReport'+import { shouldReleasePaneFocus } from '../lib/paneFocus'import { UpdateCard } from '../components/UpdateCard'import { AnnouncementBanner } from '../components/AnnouncementBanner'import { TmuxBanner } from '../components/TmuxBanner'@@ -7550,7 +7551,16 @@ export function Canvas() {publisherRef.current?.flush()markDirty()}}- onPaneClick={() => useAgentNodes.getState().select(null)}+ onPaneClick={() => {+ useAgentNodes.getState().select(null)+ // …and RELEASE THE KEYBOARD (issue #86). Clicking empty canvas used to leave a sticky+ // note's textarea focused, so everything typed afterwards went into that note — and,+ // because the canvas shortcuts all skip while an input has focus, the canvas looked+ // dead as well. Only real editing surfaces are blurred; see `shouldReleasePaneFocus`.+ if (shouldReleasePaneFocus(document.activeElement)) {+ ;(document.activeElement as HTMLElement).blur()+ }+ }}onPaneContextMenu={onPaneContextMenu}onNodeContextMenu={onNodeContextMenu}onSelectionContextMenu={onSelectionContextMenu}diff --git a/src/renderer/lib/paneFocus.test.ts b/src/renderer/lib/paneFocus.test.tsnew file mode 100644index 000000000..f68abebaa--- /dev/null+++ b/src/renderer/lib/paneFocus.test.ts@@ -0,0 +1,31 @@+import { describe, expect, it } from 'vitest'+import { shouldReleasePaneFocus } from './paneFocus'++const el = (tagName: string, contentEditable = false): Element =>+ ({ tagName, isContentEditable: contentEditable }) as unknown as Element++/**+ * Issue #86: a click on empty canvas left a sticky note's textarea focused, so everything typed+ * afterwards went into the note — noticed as spaces (a Figma space-to-pan reflex) landing in a note+ * the user had not touched, but it applies to every key, and it also kept the canvas shortcuts+ * suppressed the whole time.+ */+describe('shouldReleasePaneFocus', () => {+ it('releases a text-entry surface — the one that swallows typing', () => {+ expect(shouldReleasePaneFocus(el('TEXTAREA'))).toBe(true)+ expect(shouldReleasePaneFocus(el('INPUT'))).toBe(true)+ expect(shouldReleasePaneFocus(el('DIV', true))).toBe(true)+ })++ it('leaves anything else alone', () => {+ // Blurring a focused button or node div would fight the browser's own focus handling for no+ // gain: neither of them eats a keystroke.+ expect(shouldReleasePaneFocus(el('BUTTON'))).toBe(false)+ expect(shouldReleasePaneFocus(el('DIV'))).toBe(false)+ expect(shouldReleasePaneFocus(el('BODY'))).toBe(false)+ })++ it('answers false when nothing is focused, so the common click costs nothing', () => {+ expect(shouldReleasePaneFocus(null)).toBe(false)+ })+})diff --git a/src/renderer/lib/paneFocus.ts b/src/renderer/lib/paneFocus.tsnew file mode 100644index 000000000..2c6219d69--- /dev/null+++ b/src/renderer/lib/paneFocus.ts@@ -0,0 +1,24 @@+/**+ * Should a click on the EMPTY canvas take the keyboard away from `active`?+ *+ * Issue #86 — a user holding space to pan (a Figma reflex; this canvas has no space-pan) watched+ * the spaces land in a sticky note they were not editing. The note had DOM focus from earlier and+ * nothing ever took it back: `onPaneClick` cleared the agent selection and left the focused element+ * exactly where it was, so every keystroke after clicking away still went into that textarea.+ *+ * Space is only how it was noticed. The same focus keeps every canvas shortcut suppressed too —+ * undo, ⌘T, Delete all skip while an input has the keyboard — so from the user's side the canvas+ * had simply stopped responding.+ *+ * True only for a real EDITING surface. A button or a node div that happens to be focused is+ * harmless and blurring it would fight the browser's own focus handling; a `textarea`, an `input`+ * or a `contenteditable` is the one that swallows typing.+ *+ * `null`/`body` is the already-correct state and answers false, so the common click costs nothing.+ */+export function shouldReleasePaneFocus(active: Element | null): boolean {+ if (!active) return false+ const tag = active.tagName+ if (tag === 'TEXTAREA' || tag === 'INPUT') return true+ return (active as HTMLElement).isContentEditable === true+}diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsxindex c62a87aa7..82eae9971 100644--- a/src/renderer/nodes/TerminalNode.tsx+++ b/src/renderer/nodes/TerminalNode.tsx@@ -474,6 +474,17 @@ 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+interface CoState {/** The pty runs at a SMALLER subscriber's grid than we could fit → center + letterbox. */letterbox: boolean@@ -624,6 +635,8 @@ export function TerminalNode({const hiddenHeaderButtons = useSettings((s) => s.settings.hiddenHeaderButtons)const accountChip = accountChipLabel(data.accountId, claudeAccounts)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@@ -2611,6 +2624,19 @@ export function TerminalNode({)// ---- hover guard: dwell before entering the terminal ----+ /**+ * Take the keyboard: leave the guard, focus xterm, and report the node active.+ *+ * Split out of `onBodyEnter` so a deliberate CLICK can run it with no delay — see `onGuardUp`.+ */+ const enterNow = () => {+ if (dwellRef.current) clearTimeout(dwellRef.current)+ setArmed(false)+ termRef.current?.focus()+ useAgentStatus.getState().setActive(id, true)+ useAgentStatus.getState().clearUnread(id)+ presence.reportFocus(id)+ }const onBodyEnter = () => {if (dwellRef.current) clearTimeout(dwellRef.current)const enter = () => {@@ -2639,9 +2665,34 @@ export function TerminalNode({presence.releaseFocus(id)}// While armed, a mousedown might start a node drag — pause the dwell timer so the- // terminal doesn't grab focus mid-drag; restart it on release.- const onGuardDown = () => {+ // terminal doesn't grab focus mid-drag; the release decides what happens next (`onGuardUp`).+ const onGuardDown = (e: React.MouseEvent) => {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.+ *+ * Issue #87 — "selecting a terminal node doesn't reliably move keyboard focus; often I have to+ * click several times". It was worse than unreliable, it was self-defeating: the release used to+ * restart the full `panHoverDelay` (600 ms by default) and the next mousedown CANCELLED it, so+ * clicking again — the natural response to "it didn't focus" — actively pushed focus further+ * away. Only holding still for the whole dwell ever worked.+ *+ * The guard exists for a mouse PASSING OVER a terminal on its way somewhere (and for drags that+ * 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.+ */+ 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()}// ---- file drop: paste dropped file paths into the terminal (native-terminal behavior) ----@@ -3277,8 +3328,8 @@ export function TerminalNode({<divclassName="term-hover-guard"onMouseDown={onGuardDown}- onMouseUp={onBodyEnter}- title="Drag to move · scroll to pan · hover to focus"+ onMouseUp={onGuardUp}+ title="Click to type · drag to move · scroll to pan"/>)}{mdMode &&