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): frame a maximized node against the rectangle maximize placed it in
enesfa392b55fea9
diff --git a/CLAUDE.md b/CLAUDE.mdindex 3b2337c04..90318847a 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -3190,6 +3190,23 @@ the Settings section and ShortcutsPanel start disagreeing about what a chord mealosing the centre. The free-rect solve (`solveFitFrame` / `solveFitPadding`) stays where it earnsits keep: `fitAll`, which fits EVERY node and would otherwise tuck them under the dock.Unknowable size or no pane ⇒ the camera **stands still**.+ **ONE exception, and it is not a walk-back of that rule (issue #743): a MAXIMIZED node**+ (`isMaximized` — `data.premaxRect`, the flag `maximizeNodeToRect` writes and+ `restoreMaximizedNode` clears) is framed against the same rectangle `maximizeTargetRect` placed+ it in, by passing `measurePinnedInsets(box)` to `viewportForRect`. The trade-off above rests on+ ONE number — how much of the node ends up behind the panel — and for a maximized node that+ number is set by the PANEL rather than the node, **by construction**: maximize sized it to be+ *exactly* the free area, so centring it in the wider pane buries half the inset less the margin.+ Measured by the reporter on a signed v0.3.5 build with the sidebar pinned: an ordinary node lost+ 33px, the maximized one 137px, and the camera drifted by `322 / 2 = 161` px on every "go to+ another node and back". Because the node is that rectangle minus two margins, centring it in the+ free area reproduces maximize's own origin (`marginPx + insets.left`) exactly — which is what+ makes this a fix rather than a second opinion about placement. It applies to BOTH zoom branches+ (the rectangle question is the same one; splitting it would be two rectangles again, which is+ the bug), and with no pinned panel `insets` is zero and the whole thing is a mathematical no-op.+ A pane narrower than the panels over it falls back to the whole pane rather than solving against+ a negative width. `measurePinnedInsets` reads the DOM, so it is asked only for a node that can+ use the answer.`settings.focusZoomToNode` (Behavior, default ON) is the escape hatch for the rescale: off, thecamera keeps the zoom `getZoom()` reports and only pans, and that zoom is passed through**unclamped** — it is one the canvas is already displaying, and re-clamping it to the framingdiff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex 935437c8f..435fe36a8 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -291,13 +291,14 @@ import {} from '../lib/projectOpen'import {absolutePosition,+ isMaximized,isMeasured,nodeFitRect,viewportForRect,type FocusableNode} from '../lib/nodeFocus'import { NODE_MAXIMIZE_MARGIN_PX, maximizeTargetRect } from '../lib/nodeMaximize'-import { measurePinnedInsets, type ScreenInsets } from '../lib/pinnedInsets'+import { NO_INSETS, measurePinnedInsets, type ScreenInsets } from '../lib/pinnedInsets'import { ZONE_GUTTER_PX, ZONES, zoneTargetRect, type ZoneId } from '../lib/nodeZones'import {recordBreadcrumb,@@ -6904,7 +6905,11 @@ export function Canvas() {// `focusZoomToNode` off: keep the zoom the user settled on and only pan — the node still// lands in the middle, only the rescale is dropped.const keepZoom = useSettings.getState().settings.focusZoomToNode ? undefined : getZoom()- const viewport = viewportForRect(rect, box.width, box.height, keepZoom)+ // A MAXIMIZED node is framed against the rectangle its own placement used (issue #743);+ // everything else is centred in the whole pane, as it always was. `measurePinnedInsets`+ // reads the DOM, so it is asked only for the node that can use the answer.+ const insets = isMaximized(node) ? measurePinnedInsets(box) : NO_INSETS+ const viewport = viewportForRect(rect, box.width, box.height, keepZoom, insets)if (viewport) void setViewport(viewport, { duration: 300 })},[setViewport, getInternalNode, getZoom]diff --git a/src/renderer/canvas/canvas-wiring.test.tsx b/src/renderer/canvas/canvas-wiring.test.tsxindex dad80a0d5..684aa5b26 100644--- a/src/renderer/canvas/canvas-wiring.test.tsx+++ b/src/renderer/canvas/canvas-wiring.test.tsx@@ -178,11 +178,23 @@ describe('breadcrumb wiring the CLAUDE.md bullet calls load-bearing', () => {CANVAS_SRC.indexOf('const frameNode = useCallback'),CANVAS_SRC.indexOf('const goToNode = useCallback'))- expect(frame).toContain('viewportForRect(rect, box.width, box.height, keepZoom)')+ expect(frame).toContain('viewportForRect(rect, box.width, box.height, keepZoom, insets)')expect(frame).not.toContain('solveFitFrame')expect(frame).toContain('settings.focusZoomToNode ? undefined : getZoom()')})+ it('insets that framing ONLY for a maximized node (issue #743)', () => {+ // The trade-off above is about how much of the node ends up behind the panel, and for a+ // maximized node that number is set by the PANEL, not the node: it is exactly as wide as the+ // free area, so centring it in the wider pane buries half the inset less the margin. Keying+ // on anything looser would walk back the whole-pane rule for ordinary nodes.+ const frame = CANVAS_SRC.slice(+ CANVAS_SRC.indexOf('const frameNode = useCallback'),+ CANVAS_SRC.indexOf('const goToNode = useCallback')+ )+ expect(frame).toContain('const insets = isMaximized(node) ? measurePinnedInsets(box) : NO_INSETS')+ })+it('the resume card slot is spent only on a card that can render, and only when opted in', () => {// Gated on settings.showResumeCard (default off) FIRST — a disabled card must not spend the// one-shot slot — then once per app run, only with a live stop, and never under the opaquediff --git a/src/renderer/lib/nodeFocus.test.ts b/src/renderer/lib/nodeFocus.test.tsindex 6e533de38..6cdf9a3d2 100644--- a/src/renderer/lib/nodeFocus.test.ts+++ b/src/renderer/lib/nodeFocus.test.ts@@ -3,11 +3,13 @@ import { getViewportForBounds } from '@xyflow/system'import {FIT_NODE_OPTIONS,absolutePosition,+ isMaximized,isMeasured,nodeFitRect,viewportForRect} from './nodeFocus'import type { FocusableNode } from './nodeFocus'+import { NODE_MAXIMIZE_MARGIN_PX } from './nodeMaximize'const term = (over: Partial<FocusableNode> = {}): FocusableNode => ({id: 'n1',@@ -192,3 +194,80 @@ describe('isMeasured', () => {expect(isMeasured(undefined)).toBe(false)})})++describe('viewportForRect — the maximized exception (issue #743)', () => {+ /**+ * The reporter's controlled measurement, reproduced as arithmetic. macOS, signed v0.3.5,+ * `focusZoomToNode` OFF (so the zoom is held and cannot confound it), sessions sidebar pinned,+ * one node, maximized. Only the CAMERA moved across "go to another node and back": the node's+ * position, size and the zoom were byte-identical before and after.+ */+ const PANE_W = 1710+ const ZOOM = 0.7345+ const INSETS = { left: 322, right: 0 }+ const rect = { x: -68.9, y: 0, width: 1824, height: 1261 }+ /** Where the node's left edge lands on screen for a given viewport. */+ const leftEdge = (vp: { x: number }) => vp.x + rect.x * ZOOM++ it('reproduces the reported drift when the framing ignores the pinned inset', () => {+ // 1824 × 0.7345 = 1339.8 rendered px; (1710 - 1339.8) / 2 = 185.1 — centred in the WHOLE pane,+ // exactly as measured. Maximize had put it at 346.0, so the camera moved 160.9 px, which is+ // 322 / 2: half the left inset, what centring a free-area-wide object in the full pane gives.+ const vp = viewportForRect(rect, PANE_W, 900, ZOOM)!+ expect(leftEdge(vp)).toBeCloseTo(185.1, 0)+ expect(leftEdge(viewportForRect(rect, PANE_W, 900, ZOOM, INSETS)!) - leftEdge(vp)).toBeCloseTo(+ 160.9,+ 0+ )+ })++ it('frames a maximized node exactly where maximizeTargetRect placed it', () => {+ // maximize's own origin is `marginPx + insets.left` = 24 + 322 = 346. The node is the free+ // area minus two margins, so centring it in the free area reproduces that origin — which is+ // the property that makes this a fix rather than a different opinion about where to put it.+ const vp = viewportForRect(rect, PANE_W, 900, ZOOM, INSETS)!+ expect(leftEdge(vp)).toBeCloseTo(NODE_MAXIMIZE_MARGIN_PX + INSETS.left, 0)+ // 136.9 px of the node sat behind the sidebar before; none does now.+ expect(leftEdge(vp)).toBeGreaterThanOrEqual(INSETS.left)+ })++ it('is a mathematical no-op when no panel is pinned', () => {+ const bare = viewportForRect(rect, PANE_W, 900, ZOOM)!+ const zero = viewportForRect(rect, PANE_W, 900, ZOOM, { left: 0, right: 0 })!+ expect(zero).toEqual(bare)+ expect(viewportForRect(rect, PANE_W, 900, undefined, { left: 0, right: 0 })).toEqual(+ viewportForRect(rect, PANE_W, 900)+ )+ })++ it('insets the zoom-to-fit path too, without changing the unpinned answer', () => {+ // `focusZoomToNode` ON rescales as well. The rectangle question is the same one, so the+ // maximized node is fitted INSIDE the free area rather than the pane — its whole width is+ // clear of the panel, where centring in the pane left part of it underneath.+ const fitted = viewportForRect(rect, PANE_W, 900, undefined, INSETS)!+ expect(fitted.x + rect.x * fitted.zoom).toBeGreaterThanOrEqual(INSETS.left)+ expect(fitted.x + (rect.x + rect.width) * fitted.zoom).toBeLessThanOrEqual(PANE_W)+ })++ it('falls back to the whole pane when the panels are wider than it', () => {+ // Not a rectangle anything can be centred in — solving against a negative width would put the+ // camera somewhere arbitrary. Standing on the old answer is the honest degrade.+ const narrow = viewportForRect(rect, 300, 900, ZOOM, { left: 322, right: 0 })!+ expect(narrow).toEqual(viewportForRect(rect, 300, 900, ZOOM))+ })++ it('refuses a container it cannot size, insets or not', () => {+ expect(viewportForRect(rect, 0, 0, ZOOM, INSETS)).toBeNull()+ expect(viewportForRect(rect, PANE_W, 900, 0, INSETS)).toBeNull()+ })+})++describe('isMaximized', () => {+ it('keys on premaxRect — the flag maximize itself writes and restore clears', () => {+ expect(isMaximized({ data: { premaxRect: { x: 0, y: 0, width: 10, height: 10 } } })).toBe(true)+ expect(isMaximized({ data: {} })).toBe(false)+ expect(isMaximized({})).toBe(false)+ expect(isMaximized(null)).toBe(false)+ expect(isMaximized(undefined)).toBe(false)+ })+})diff --git a/src/renderer/lib/nodeFocus.ts b/src/renderer/lib/nodeFocus.tsindex a34e531fd..af0a813b7 100644--- a/src/renderer/lib/nodeFocus.ts+++ b/src/renderer/lib/nodeFocus.ts@@ -1,5 +1,7 @@import { getViewportForBounds, type Rect, type Viewport } from '@xyflow/system'+import { NO_INSETS, type ScreenInsets } from './pinnedInsets'+/*** "Zoom to this node" geometry, computed without React Flow's `fitView`.*@@ -35,6 +37,26 @@ export interface FocusableNode {style?: { width?: number | string | null; height?: number | string | null }}+/**+ * Is this node currently MAXIMIZED — i.e. was it placed against the chrome-free rectangle rather+ * than dropped somewhere by hand?+ *+ * `premaxRect` is the maximize MODE flag (`maximizeNodeToRect` writes it, `restoreMaximizedNode`+ * clears it), which is what makes it the right key here: it is exactly the set of nodes whose+ * position was chosen by `maximizeTargetRect`, and the fix below is about framing a node against+ * the rectangle its own placement used.+ *+ * It survives things that make the node no longer free-area-sized — a manual resize, a window+ * resize (maximize deliberately does not re-fit on those) — and that is acceptable in both+ * directions: with no pinned panel the inset is zero and this decision is a no-op, and with one+ * the worst case is a node framed clear of a panel it was already meant to clear. Unpinning the+ * panel needs no special case at all: `fitMaximizedToUsableArea` re-fits every maximized node+ * whenever the insets change, so the flag and the geometry re-converge on their own.+ */+export function isMaximized(node: { data?: { premaxRect?: unknown } } | null | undefined): boolean {+ return !!node?.data?.premaxRect+}+/** Zoom/padding for framing a single node, shared by both framing paths here so the whole-pane* and chrome-free-frame answers cannot drift apart: the clamp keeps a small node from filling the* screen and a huge one from being fit microscopic. */@@ -93,13 +115,24 @@ export function nodeFitRect(node: FocusableNode, all: readonly FocusableNode[]):* The viewport that frames `rect` in a `containerWidth × containerHeight` pane, with the same* padding/zoom clamp `fitView` would have applied. Null when the container has no size yet.*- * **Centred in the pane, and nothing else.** Framing a focused node against the chrome-free- * rectangle instead — centred in it, or centred in the pane and then nudged clear of it — was tried- * twice and is wrong both ways: the sessions sidebar is a 300px OVERLAY, so either rule pushes the- * node right by most of its width, and "go to node" stops putting the node where the eye is. The- * couple of dozen pixels of a node that end up behind the sidebar cost far less than that. The- * free-rect solve stays where it earns its keep, in `fitAll`, which fits EVERY node and would- * otherwise tuck them under the dock.+ * **Centred in the pane, and nothing else — `insets` default to none.** Framing a focused node+ * against the chrome-free rectangle instead — centred in it, or centred in the pane and then+ * nudged clear of it — was tried twice and is wrong both ways: the sessions sidebar is a 300px+ * OVERLAY, so either rule pushes the node right by most of its width, and "go to node" stops+ * putting the node where the eye is. The couple of dozen pixels of a node that end up behind the+ * sidebar cost far less than that. The free-rect solve stays where it earns its keep, in `fitAll`,+ * which fits EVERY node and would otherwise tuck them under the dock.+ *+ * **The MAXIMIZED exception (issue #743), and why it is not a walk-back of that trade-off.** The+ * trade-off above rests on one number: how much of the node ends up behind the panel. For an+ * ordinary node that is a couple of dozen pixels (33px, measured by the reporter). For a maximized+ * one the premise inverts by CONSTRUCTION, not by degree: `maximizeTargetRect` sized the node to+ * be *exactly* as wide as the free area, so centring it in the wider pane buries half the inset+ * less the margin — 137px in the reported layout, and it scales with the PANEL, not with the node.+ * It cannot come out as a few dozen pixels. So a maximized node is framed against the same+ * rectangle its own placement used, which — since the node is that rectangle minus two margins —+ * reproduces exactly where maximize put it. Everything else still centres in the whole pane,+ * because `insets` is `NO_INSETS` unless the caller says otherwise.** `zoom` keeps the camera at a scale the caller already has (`settings.focusZoomToNode` off): the* node is centred exactly as it would be, at that zoom, so "go to" stays a pan. It is passed@@ -110,25 +143,32 @@ export function viewportForRect(rect: Rect,containerWidth: number,containerHeight: number,- zoom?: number+ zoom?: number,+ insets: ScreenInsets = NO_INSETS): Viewport | null {if (!(containerWidth > 0) || !(containerHeight > 0)) return null+ // A pane narrower than the panels covering it is not a rectangle anything can be centred in —+ // fall back to the whole pane rather than solving against a negative width.+ const freeWidth = containerWidth - insets.left - insets.right+ const originX = freeWidth > 0 ? insets.left : 0+ const width = freeWidth > 0 ? freeWidth : containerWidthif (zoom !== undefined) {if (!(zoom > 0)) return nullreturn {- x: containerWidth / 2 - (rect.x + rect.width / 2) * zoom,+ x: originX + width / 2 - (rect.x + rect.width / 2) * zoom,y: containerHeight / 2 - (rect.y + rect.height / 2) * zoom,zoom}}- return getViewportForBounds(+ const fitted = getViewportForBounds(rect,- containerWidth,+ width,containerHeight,FIT_NODE_OPTIONS.minZoom,FIT_NODE_OPTIONS.maxZoom,FIT_NODE_OPTIONS.padding)+ return originX ? { ...fitted, x: fitted.x + originX } : fitted}/** Whether React Flow already knows this node's on-screen size — i.e. whether `fitView` will