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): the terminal node's comments composer keeps the keyboard
review165348f3ecf3
diff --git a/src/renderer/lib/terminalFocusMode.test.ts b/src/renderer/lib/terminalFocusMode.test.tsindex 9e32cd1ee..d66d3a100 100644--- a/src/renderer/lib/terminalFocusMode.test.ts+++ b/src/renderer/lib/terminalFocusMode.test.ts@@ -100,6 +100,7 @@ describe('terminal focus mode (#757)', () => {const ev = (over: Partial<Parameters<typeof focusLossOutcome>[0]>) =>focusLossOutcome({nodeRoot,+ nodeChrome: null,lost,gained: null,activeElement: body,@@ -110,6 +111,22 @@ describe('terminal focus mode (#757)', () => {...over})+ it('keeps when focus moved into a field beside the root but inside the node (comments flyout)', () => {+ const composer = { id: 'comments-composer' }+ // The wrapper is the chrome: a header press focuses the very element passed as nodeChrome.+ const nodeChrome: { id: string; contains: (n: unknown) => boolean } = {+ id: 'react-flow-node-wrapper',+ contains: (n) => n === nodeChrome || n === composer || nodeRoot.contains(n)+ }+ // The press landed in the node's wrapper, which used to read as "own chrome" → reclaim → the+ // xterm took the keyboard back and the composer could never be typed into.+ expect(ev({ nodeChrome, gained: composer, activeElement: composer, pressedInOwnNode: true })).toBe('keep')+ // A press on the header/border still sends focus to the wrapper itself, and that still reclaims.+ expect(ev({ nodeChrome, gained: nodeChrome, activeElement: nodeChrome, pressedInOwnNode: true })).toBe('reclaim')+ // Another card is still elsewhere.+ expect(ev({ nodeChrome, gained: elsewhere, activeElement: elsewhere })).toBe('release')+ })+it('releases when focus moved to something outside the node (another card, a field)', () => {expect(ev({ gained: elsewhere, activeElement: elsewhere })).toBe('release')})diff --git a/src/renderer/lib/terminalFocusMode.ts b/src/renderer/lib/terminalFocusMode.tsindex fc2ca0c71..18fd62745 100644--- a/src/renderer/lib/terminalFocusMode.ts+++ b/src/renderer/lib/terminalFocusMode.ts@@ -89,6 +89,9 @@ export interface NodeRootLike {export interface FocusLossEvent {/** The node's root (`.term-node`), or null if it is gone. */nodeRoot: NodeRootLike | null+ /** The node's React Flow wrapper (`.react-flow__node`), which also holds the root's SIBLINGS —+ * the 💬 comments flyout sits outside the root (overflow:hidden would clip it) but inside this. */+ nodeChrome: NodeRootLike | null/** The element that lost focus (`focusout`'s target). */lost: unknown/** Where focus went (`focusout`'s `relatedTarget`); null for "nowhere" AND for a window blur. */@@ -129,7 +132,7 @@ export type FocusLossOutcome =* a real move from its look-alikes:** - **Focus stayed inside the node** (the header's rename field, a header button, the ⌘M view's- * composer). The user is still working HERE → `keep`.+ * composer, the 💬 comments flyout beside the root). The user is still working HERE → `keep`.* - **The window lost focus** (Cmd+Tab, a click on another app). Chromium fires `blur`/`focusout`* on the focused element, but that element remains `document.activeElement` and is focused* again on return — the terminal never stopped owning the keyboard → `keep`.@@ -157,6 +160,11 @@ export function focusLossOutcome(e: FocusLossEvent): FocusLossOutcome {if (e.lostIsCoveredXterm) return 'keep'if (e.activeElement === e.lost) return 'keep'if (e.gained && e.nodeRoot.contains(e.gained)) return 'keep'+ // Focus went to a field this node renders beside its root (the comments composer). The wrapper+ // ITSELF is excluded: that is where a header/border press sends focus, and it must still reclaim.+ // Without this the press read as "own chrome" and `reclaim` put the keyboard back in the xterm+ // a tick later — the composer's caret blinked once and nothing could be typed.+ if (e.gained && e.nodeChrome && e.gained !== e.nodeChrome && e.nodeChrome.contains(e.gained)) return 'keep'if (e.pressedInOwnNode) return e.pressedInReadableText ? 'reclaim-on-release' : 'reclaim'return 'release'}diff --git a/src/renderer/nodes/useClickToFocus.ts b/src/renderer/nodes/useClickToFocus.tsindex d23476574..cd7cd40e9 100644--- a/src/renderer/nodes/useClickToFocus.ts+++ b/src/renderer/nodes/useClickToFocus.ts@@ -125,6 +125,7 @@ export function useClickToFocus(host: ClickToFocusHost): void {if (h().reparenting()) returnconst outcome = focusLossOutcome({nodeRoot: root,+ nodeChrome: root.closest('.react-flow__node'),lost: e.target,gained: e.relatedTarget,activeElement: document.activeElement,