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): go to node centres the node, full stop
Bas Milius1c248da74ee2
diff --git a/CLAUDE.md b/CLAUDE.mdindex ca5ca002d..7d0206420 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -2704,13 +2704,15 @@ the Settings section and ShortcutsPanel start disagreeing about what a chord meawhen it has one (`getInternalNode` — `measured` reaches OUR node objects one render later via`onNodesChange`, and `internals.positionAbsolute` also accounts for `extent:'parent'` clamping),else `nodeFitRect` from the PERSISTED size, resolving the group-parent chain. Then- `viewportForRectClearOf`: **centred in the SCREEN**, and only nudged — by the smallest amount- that works — when the centred node would slide under the floating chrome (the chrome-free frame- comes from `solveFitFrame`, pane-local, the same solve `fitAll`'s padding is expressed through).- Centring in that FRAME instead was tried and is wrong: the free rect is whatever the dock and the- sidebar leave over, not where the eye looks, so a node landed too far right on an ultrawide and- half off-screen on a laptop. A node too large for the frame is left centred — a shift there only- swaps which edge is covered. Unknowable size or no pane ⇒ the camera **stands still**.+ `viewportForRect`: **centred in the pane, and nothing else.** Framing a single focused node+ against the chrome-free rectangle was tried twice and is wrong both ways — centred IN that rect+ ("too far right on an ultrawide, half off-screen on a laptop") and centred in the pane then+ nudged clear of it ("still not in the middle") — because `.sessions-sidebar` is a 300px absolute+ OVERLAY and it is open exactly when this feature is used, so either rule pushes the node right by+ most of its width. The couple of dozen pixels that end up behind the sidebar cost far less than+ losing the centre. The free-rect solve (`solveFitFrame` / `solveFitPadding`) stays where it earns+ its keep: `fitAll`, which fits EVERY node and would otherwise tuck them under the dock.+ Unknowable size or no pane ⇒ the camera **stands still**.`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 f9bd3b500..fa4c5eb92 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -36,7 +36,7 @@ import {isSessionReady,subscribeSessionReady} from '../nodes/TerminalNode'-import { solveFitFrame, solveFitPadding } from './fit-view'+import { solveFitPadding } from './fit-view'import { FloatingEdge } from './FloatingEdge'import { MacWheelGestureRouter, trackpadRoutingEnabled } from './wheel-gesture'import { isBrowserRuntime } from '@renderer/bridge/runtime'@@ -269,7 +269,6 @@ import {isMeasured,nodeFitRect,viewportForRect,- viewportForRectClearOf,type FocusableNode} from '../lib/nodeFocus'import { NODE_MAXIMIZE_MARGIN_PX, maximizeTargetRect } from '../lib/nodeMaximize'@@ -6674,16 +6673,10 @@ export function Canvas() {// teleporting the user to the origin, which is the failure this whole path exists for.if (!rect || !wrap) returnconst box = wrap.getBoundingClientRect()- // `focusZoomToNode` off: keep the zoom the user settled on and only pan. The node is still- // centred and still kept clear of the chrome — only the rescale is dropped.+ // `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 = viewportForRectClearOf(- rect,- box.width,- box.height,- solveFitFrame(wrap, rect.width, rect.height),- keepZoom- )+ const viewport = viewportForRect(rect, box.width, box.height, keepZoom)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 a562b986a..dad80a0d5 100644--- a/src/renderer/canvas/canvas-wiring.test.tsx+++ b/src/renderer/canvas/canvas-wiring.test.tsx@@ -170,14 +170,16 @@ describe('breadcrumb wiring the CLAUDE.md bullet calls load-bearing', () => {expect(frame).toContain('setViewport(viewport, { duration: 300 })')})- it('frames the node in the SCREEN, honouring the keep-my-zoom setting', () => {- // Centring in the chrome-free rect instead read as "too far right" on a wide display and as- // half off-screen on a laptop; `viewportForRectClearOf` centres in the pane and only nudges.+ it('centres the node in the pane and never solves chrome around it', () => {+ // Framing a single focused node against the chrome-free rectangle was reported wrong twice+ // ("too far right", "not in the middle"): the sessions sidebar is a 300px overlay and it is+ // open exactly when this is used. The free-rect solve stays in fitAll, which fits every node.const frame = CANVAS_SRC.slice(CANVAS_SRC.indexOf('const frameNode = useCallback'),CANVAS_SRC.indexOf('const goToNode = useCallback'))- expect(frame).toContain('viewportForRectClearOf(')+ expect(frame).toContain('viewportForRect(rect, box.width, box.height, keepZoom)')+ expect(frame).not.toContain('solveFitFrame')expect(frame).toContain('settings.focusZoomToNode ? undefined : getZoom()')})diff --git a/src/renderer/lib/nodeFocus.test.ts b/src/renderer/lib/nodeFocus.test.tsindex 6973f93cb..6e533de38 100644--- a/src/renderer/lib/nodeFocus.test.ts+++ b/src/renderer/lib/nodeFocus.test.ts@@ -5,8 +5,7 @@ import {absolutePosition,isMeasured,nodeFitRect,- viewportForRect,- viewportForRectClearOf+ viewportForRect} from './nodeFocus'import type { FocusableNode } from './nodeFocus'@@ -149,48 +148,26 @@ describe('viewportForRect', () => {})})-describe('viewportForRectClearOf', () => {+describe('viewportForRect — the framing "go to node" applies', () => {const rect = { x: 5000, y: 4000, width: 600, height: 400 }- // A sessions sidebar on the left, as the free-rect solver reports it: pane-local coordinates.- const sidebar = (left: number, paneW: number, paneH: number) => ({- left,- top: 12,- right: paneW - 12,- bottom: paneH - 12- })-- it('centres the node in the SCREEN, not in the chrome-free rectangle', () => {- // The regression this pins: framing a node in the middle of the free rect reads as "too far- // right" on a wide display — the free rect is whatever the dock and the sidebar leave over,- // which is not where the eye looks. On an ultrawide the centred node clears the chrome by- // itself, so the answer must be the plain centred one.- const vp = viewportForRectClearOf(rect, 3440, 1400, sidebar(352, 3440, 1400))!- expect(vp).toEqual(viewportForRect(rect, 3440, 1400))- expect(vp.x + 5300 * vp.zoom).toBeCloseTo(1720, 0)- expect(vp.y + 4200 * vp.zoom).toBeCloseTo(700, 0)- })-- it('nudges just enough to clear a panel the centred node would slide under', () => {- const frame = sidebar(500, 1440, 900)- const vp = viewportForRectClearOf(rect, 1440, 900, frame)!- const centred = viewportForRect(rect, 1440, 900)!- // Flush against the panel — moved, and no further than it had to be.- expect(vp.x + rect.x * vp.zoom).toBeCloseTo(frame.left, 0)- expect(vp.x).toBeGreaterThan(centred.x)- // The zoom and the other axis are untouched: this is a nudge, not a second framing.- expect(vp.zoom).toBe(centred.zoom)- expect(vp.y).toBe(centred.y)- })-- it('leaves a node too large for the frame centred — a shift only swaps the covered edge', () => {- const vp = viewportForRectClearOf(rect, 1440, 900, { left: 600, top: 12, right: 900, bottom: 888 })- expect(vp).toEqual(viewportForRect(rect, 1440, 900))++ it('centres the node in the pane, whatever chrome floats over it', () => {+ // Twice-reported regression: framing against the chrome-free rectangle — centred in it, or+ // centred in the pane and then nudged clear of it — pushes the node right by most of its width,+ // because the sessions sidebar is a 300px OVERLAY and it is open exactly when this is used.+ // "Go to node" puts the node where the eye is; the free-rect solve belongs to fitAll.+ const wide = viewportForRect(rect, 3440, 1400)!+ expect(wide.x + 5300 * wide.zoom).toBeCloseTo(1720, 0)+ expect(wide.y + 4200 * wide.zoom).toBeCloseTo(700, 0)+ const laptop = viewportForRect(rect, 1440, 900)!+ expect(laptop.x + 5300 * laptop.zoom).toBeCloseTo(720, 0)+ expect(laptop.y + 4200 * laptop.zoom).toBeCloseTo(450, 0)})it('keeps a given zoom and only pans (settings.focusZoomToNode off)', () => {// The point of the option: a user who settled on a zoom level loses their sense of place when- // a jump also rescales the canvas. The node is still centred, and still nudged clear of chrome.- const vp = viewportForRectClearOf(rect, 1440, 900, sidebar(352, 1440, 900), 0.5)!+ // a jump also rescales the canvas. The node is still centred.+ const vp = viewportForRect(rect, 1440, 900, 0.5)!expect(vp.zoom).toBe(0.5)expect(vp.x + 5300 * 0.5).toBeCloseTo(720, 0)expect(vp.y + 4200 * 0.5).toBeCloseTo(450, 0)@@ -199,14 +176,9 @@ describe('viewportForRectClearOf', () => {it('passes an out-of-framing-range zoom through — it is one the canvas already shows', () => {// Re-clamping to FIT_NODE_OPTIONS would rescale the very view this option exists to leave// alone; the canvas's own limits already bound what getZoom() can return.- expect(viewportForRectClearOf(rect, 1440, 900, null, 1.9)!.zoom).toBe(1.9)- expect(viewportForRectClearOf(rect, 1440, 900, null, 0.1)!.zoom).toBe(0.1)- expect(viewportForRectClearOf(rect, 1440, 900, null, 0)).toBeNull()- })-- it('is the plain centred answer when there is no frame to solve', () => {- expect(viewportForRectClearOf(rect, 1440, 900, null)).toEqual(viewportForRect(rect, 1440, 900))- expect(viewportForRectClearOf(rect, 0, 0, sidebar(352, 1440, 900))).toBeNull()+ expect(viewportForRect(rect, 1440, 900, 1.9)!.zoom).toBe(1.9)+ expect(viewportForRect(rect, 1440, 900, 0.1)!.zoom).toBe(0.1)+ expect(viewportForRect(rect, 1440, 900, 0)).toBeNull()})})diff --git a/src/renderer/lib/nodeFocus.ts b/src/renderer/lib/nodeFocus.tsindex ced8bc973..a34e531fd 100644--- a/src/renderer/lib/nodeFocus.ts+++ b/src/renderer/lib/nodeFocus.ts@@ -93,6 +93,14 @@ 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.+ ** `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* through UNCLAMPED — it is a zoom the canvas is already displaying, and re-clamping it to the@@ -123,54 +131,6 @@ export function viewportForRect()}-/** A rectangle inside the flow pane, in the pane's OWN coordinates (0,0 = its top-left) — the- * chrome-free area a node should be framed into. Structurally the `FitRect` of `canvas/fit-view`,- * restated here so this module stays free of anything that touches the DOM. */-export interface FitFrame {- left: number- top: number- right: number- bottom: number-}--/** The shift that brings a `size`-long span starting at `start` inside `[lo, hi]`, or 0 when it- * is already inside — or too long to fit, where any shift trades one clipped edge for the other. */-function shiftInto(start: number, size: number, lo: number, hi: number): number {- if (size >= hi - lo) return 0- if (start < lo) return lo - start- if (start + size > hi) return hi - (start + size)- return 0-}--/**- * `viewportForRect`, then the SMALLEST nudge that keeps the node clear of the floating chrome.- *- * "Go to node" means putting the node in front of the user, and the middle of the screen is where- * that is: a node centred in the chrome-free rectangle instead reads as off to one side on a wide- * display (the free rect is whatever the dock and the sidebar leave over, not the eye's centre) and- * as half off-screen on a small one. So the centred answer stands, and the frame only pulls it back- * when it would otherwise slide under a panel — usually the sessions sidebar the click came from.- * A node too large to fit the frame is left centred: any shift there only swaps which edge is- * covered. `frame` null (nothing sensible to solve) ⇒ the plain centred answer.- */-export function viewportForRectClearOf(- rect: Rect,- containerWidth: number,- containerHeight: number,- frame: FitFrame | null,- zoom?: number-): Viewport | null {- const centred = viewportForRect(rect, containerWidth, containerHeight, zoom)- if (!centred || !frame) return centred- const width = rect.width * centred.zoom- const height = rect.height * centred.zoom- return {- zoom: centred.zoom,- x: centred.x + shiftInto(centred.x + rect.x * centred.zoom, width, frame.left, frame.right),- y: centred.y + shiftInto(centred.y + rect.y * centred.zoom, height, frame.top, frame.bottom)- }-}-/** Whether React Flow already knows this node's on-screen size — i.e. whether `fitView` will* actually include it in its fit set. Takes the minimal shape so it reads either a user-land* node or React Flow's own internal node (the authoritative one; see Canvas.goToNode). */