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): keep maximize and zone snap clear of pinned side panels

Erik Zwep3b67b6618826
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index e1836b311..9ed5b374b 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -248,8 +248,9 @@ import {
viewportForRect,
type FocusableNode
} from '../lib/nodeFocus'
-import { maximizeTargetRect } from '../lib/nodeMaximize'
-import { ZONES, zoneTargetRect, type ZoneId } from '../lib/nodeZones'
+import { NODE_MAXIMIZE_MARGIN_PX, maximizeTargetRect } from '../lib/nodeMaximize'
+import { measurePinnedInsets } from '../lib/pinnedInsets'
+import { ZONE_GUTTER_PX, ZONES, zoneTargetRect, type ZoneId } from '../lib/nodeZones'
import {
recordBreadcrumb,
stepBreadcrumb,
@@ -477,6 +478,7 @@ import {
sshAccountsHint,
ungroupNodes,
maximizeNodeToRect,
+ refitMaximizedNode,
restoreMaximizedNode,
placeNodeInRect,
type CanvasNode
@@ -6413,13 +6415,69 @@ export function Canvas() {
}
if (target.data.collapsed) return false
const wrap = flowWrapRef.current?.getBoundingClientRect()
- const rect = wrap ? maximizeTargetRect(getViewport(), wrap.width, wrap.height) : null
+ const rect = wrap
+ ? maximizeTargetRect(
+ getViewport(),
+ wrap.width,
+ wrap.height,
+ NODE_MAXIMIZE_MARGIN_PX,
+ measurePinnedInsets(wrap)
+ )
+ : null
if (!rect) return false
setNodes((ns) => maximizeNodeToRect(ns, target.id, rect))
markDirty()
return true
}, [placementTargetNode, setNodes, markDirty, getViewport])
+ /**
+ * Keep a maximized node fitted to the area the pinned side panels leave over.
+ *
+ * Maximize is a MODE, not a one-shot placement — a zone snap is the one-shot kind and stays
+ * where it was put. While maximize is on the node claims the whole usable canvas, so pinning a
+ * panel (the node would slide under it), unpinning one (the node would sit short of the space it
+ * just gained), or a panel simply changing width (`uiScale`, the drawer's wide variant) has to
+ * move it.
+ *
+ * A ResizeObserver rather than the pin flags alone: the explorer drawer animates in over 160ms
+ * (`nt-drawer-in`), so measuring one frame after the state change catches it mid-slide. The
+ * observer fires again as it settles. `refitMaximizedNode` is idempotent, so the extra ticks
+ * cost nothing and the workspace is only marked dirty when a node actually moved.
+ */
+ const fitMaximizedToUsableArea = useCallback(() => {
+ if (!nodesRef.current.some((n) => n.data.premaxRect)) return
+ const wrap = flowWrapRef.current?.getBoundingClientRect()
+ if (!wrap) return
+ const rect = maximizeTargetRect(
+ getViewport(),
+ wrap.width,
+ wrap.height,
+ NODE_MAXIMIZE_MARGIN_PX,
+ measurePinnedInsets(wrap)
+ )
+ if (!rect) return
+ const current = nodesRef.current
+ const fitted = current.reduce(
+ (acc, n) => (n.data.premaxRect ? refitMaximizedNode(acc, n.id, rect) : acc),
+ current
+ )
+ if (fitted === current) return
+ setNodes((ns) => ns.reduce((acc, n) => (n.data.premaxRect ? refitMaximizedNode(acc, n.id, rect) : acc), ns))
+ markDirty()
+ }, [getViewport, setNodes, markDirty])
+
+ useEffect(() => {
+ fitMaximizedToUsableArea()
+ if (typeof ResizeObserver === 'undefined') return
+ const observer = new ResizeObserver(() => fitMaximizedToUsableArea())
+ for (const el of document.querySelectorAll('.sessions-sidebar--pinned, .drawer--pinned')) {
+ observer.observe(el)
+ }
+ return () => observer.disconnect()
+ // The pin/open flags mount and unmount the panels, so they decide WHAT to observe; the
+ // observer then covers every size change of whatever is docked.
+ }, [sessionsPinned, sessionsDismissed, explorerOpen, explorer.pinned, fitMaximizedToUsableArea])
+
/**
* Zone snap (issue #394 v1): place `nodeId` (or the placement target, for the keyboard chords)
* into a zone of the visible canvas. Same declines as maximize; no toggle state — the node has
@@ -6432,7 +6490,17 @@ export function Canvas() {
: placementTargetNode()
if (!target || target.type === 'group' || target.data.collapsed) return false
const wrap = flowWrapRef.current?.getBoundingClientRect()
- const rect = wrap ? zoneTargetRect(getViewport(), wrap.width, wrap.height, zone) : null
+ const rect = wrap
+ ? zoneTargetRect(
+ getViewport(),
+ wrap.width,
+ wrap.height,
+ zone,
+ NODE_MAXIMIZE_MARGIN_PX,
+ ZONE_GUTTER_PX,
+ measurePinnedInsets(wrap)
+ )
+ : null
if (!rect) return false
setNodes((ns) => placeNodeInRect(ns, target.id, rect))
markDirty()
diff --git a/src/renderer/components/SessionsSidebar.tsx b/src/renderer/components/SessionsSidebar.tsx
index 1082a41ca..a36eb168c 100644
--- a/src/renderer/components/SessionsSidebar.tsx
+++ b/src/renderer/components/SessionsSidebar.tsx
@@ -454,7 +454,7 @@ export function SessionsSidebar(props: SessionsSidebarProps): JSX.Element | null
return (
<aside
- className="sessions-sidebar"
+ className={props.pinned ? 'sessions-sidebar sessions-sidebar--pinned' : 'sessions-sidebar'}
onMouseEnter={props.onMouseEnter}
onMouseLeave={props.onMouseLeave}
>
diff --git a/src/renderer/lib/nodeMaximize.ts b/src/renderer/lib/nodeMaximize.ts
index a4e0f12af..221e1a9f2 100644
--- a/src/renderer/lib/nodeMaximize.ts
+++ b/src/renderer/lib/nodeMaximize.ts
@@ -9,6 +9,7 @@
// 80×24 never shows one extra line).
import type { Viewport } from '@xyflow/system'
+import { NO_INSETS, type ScreenInsets } from './pinnedInsets'
/** Screen-pixel margin kept around a maximized node, so the canvas is still visibly behind it. */
export const NODE_MAXIMIZE_MARGIN_PX = 24
@@ -21,7 +22,8 @@ export interface FlowRect {
}
/**
- * The visible canvas area in FLOW coordinates, inset by `marginPx` (screen px). Null when the
+ * The visible canvas area in FLOW coordinates, inset by `marginPx` (screen px) and by whatever
+ * pinned side panels cover (`insets`). Null when the
* container has no usable size yet (first tick after mount) or is too small for a node to mean
* anything — the caller must then leave the node alone, exactly like `viewportForRect`'s null.
*/
@@ -29,16 +31,18 @@ export function maximizeTargetRect(
viewport: Viewport,
containerWidth: number,
containerHeight: number,
- marginPx: number = NODE_MAXIMIZE_MARGIN_PX
+ marginPx: number = NODE_MAXIMIZE_MARGIN_PX,
+ insets: ScreenInsets = NO_INSETS
): FlowRect | null {
if (!(viewport.zoom > 0)) return null
- const innerW = containerWidth - marginPx * 2
+ const originX = marginPx + insets.left
+ const innerW = containerWidth - marginPx * 2 - insets.left - insets.right
const innerH = containerHeight - marginPx * 2
// Below this the "maximized" node would be smaller than a default terminal's header — refuse
// rather than produce a comic-strip node the user then has to fish the restore button out of.
if (!(innerW >= 120) || !(innerH >= 120)) return null
return {
- x: (marginPx - viewport.x) / viewport.zoom,
+ x: (originX - viewport.x) / viewport.zoom,
y: (marginPx - viewport.y) / viewport.zoom,
width: innerW / viewport.zoom,
height: innerH / viewport.zoom
diff --git a/src/renderer/lib/nodeZones.test.ts b/src/renderer/lib/nodeZones.test.ts
index f449271de..dfeeef037 100644
--- a/src/renderer/lib/nodeZones.test.ts
+++ b/src/renderer/lib/nodeZones.test.ts
@@ -1,6 +1,7 @@
import { describe, it, expect } from 'vitest'
import { ZONES, ZONE_GUTTER_PX, zoneTargetRect } from './nodeZones'
import { NODE_MAXIMIZE_MARGIN_PX, maximizeTargetRect } from './nodeMaximize'
+import type { ScreenInsets } from './pinnedInsets'
// Zone snapping (issue #394 v1): the viewport→flow subdivision the keyboard chords and the
// "Snap to zone" menu both use. All screen-px assertions run at zoom 1 / camera origin so flow
@@ -84,4 +85,30 @@ describe('zoneTargetRect', () => {
expect(rect!.height).toBeGreaterThan(0)
}
})
+
+ it('subdivides the area left over by pinned side panels, not the whole wrapper', () => {
+ // A pinned sessions sidebar on the left (314px) and a pinned explorer drawer on the right
+ // (374px): zones must tile what remains, or left-half lands under the sidebar (the bug).
+ const insets: ScreenInsets = { left: 314, right: 374 }
+ const left = zoneTargetRect(VP, W, H, 'left-half', M, G, insets)!
+ const right = zoneTargetRect(VP, W, H, 'right-half', M, G, insets)!
+ expect(left.x).toBe(M + insets.left)
+ expect(right.x + right.width).toBeCloseTo(W - M - insets.right)
+ // Still one gutter between them, and still equal halves — of the smaller area.
+ expect(right.x - (left.x + left.width)).toBeCloseTo(G)
+ expect(left.width).toBeCloseTo(right.width)
+ expect(left.width).toBeCloseTo((W - 2 * M - insets.left - insets.right - G) / 2)
+ // Vertical geometry is untouched: both panels are side cards.
+ expect(left.y).toBe(M)
+ expect(left.height).toBe(H - 2 * M)
+ })
+
+ it('still agrees with maximize once panels are pinned', () => {
+ const insets: ScreenInsets = { left: 314, right: 0 }
+ const max = maximizeTargetRect(VP, W, H, M, insets)!
+ const left = zoneTargetRect(VP, W, H, 'left-half', M, G, insets)!
+ const right = zoneTargetRect(VP, W, H, 'right-half', M, G, insets)!
+ expect(left.x).toBe(max.x)
+ expect(right.x + right.width).toBeCloseTo(max.x + max.width)
+ })
})
diff --git a/src/renderer/lib/nodeZones.ts b/src/renderer/lib/nodeZones.ts
index 3ef711570..0619a7eaa 100644
--- a/src/renderer/lib/nodeZones.ts
+++ b/src/renderer/lib/nodeZones.ts
@@ -10,6 +10,7 @@
import type { Viewport } from '@xyflow/system'
import { NODE_MAXIMIZE_MARGIN_PX, type FlowRect } from './nodeMaximize'
+import { NO_INSETS, type ScreenInsets } from './pinnedInsets'
/** Screen-pixel gap between two adjacent zones, so side-by-side nodes don't touch. */
export const ZONE_GUTTER_PX = 12
@@ -63,15 +64,19 @@ export function zoneTargetRect(
containerHeight: number,
zone: ZoneId,
marginPx: number = NODE_MAXIMIZE_MARGIN_PX,
- gutterPx: number = ZONE_GUTTER_PX
+ gutterPx: number = ZONE_GUTTER_PX,
+ insets: ScreenInsets = NO_INSETS
): FlowRect | null {
const frac = ZONES_BY_ID.get(zone)
if (!frac || !(viewport.zoom > 0)) return null
- const innerW = containerWidth - marginPx * 2
+ // Same usable area as maximize: the margin on every edge, plus whatever pinned side panels
+ // cover. Zones subdivide THAT, so left-half lands beside a pinned sidebar instead of under it.
+ const originX = marginPx + insets.left
+ const innerW = containerWidth - marginPx * 2 - insets.left - insets.right
const innerH = containerHeight - marginPx * 2
- // Screen-px edges inside the margin-inset area, with internal edges pulled in by gutter/2.
- const left = marginPx + frac.x0 * innerW + (frac.x0 > 0 ? gutterPx / 2 : 0)
- const right = marginPx + frac.x1 * innerW - (frac.x1 < 1 ? gutterPx / 2 : 0)
+ // Screen-px edges inside the usable area, with internal edges pulled in by gutter/2.
+ const left = originX + frac.x0 * innerW + (frac.x0 > 0 ? gutterPx / 2 : 0)
+ const right = originX + frac.x1 * innerW - (frac.x1 < 1 ? gutterPx / 2 : 0)
const top = marginPx + frac.y0 * innerH + (frac.y0 > 0 ? gutterPx / 2 : 0)
const bottom = marginPx + frac.y1 * innerH - (frac.y1 < 1 ? gutterPx / 2 : 0)
// Same refusal floor as maximize: below this the "zone" is smaller than a node header, and a
diff --git a/src/renderer/lib/pinnedInsets.test.ts b/src/renderer/lib/pinnedInsets.test.ts
new file mode 100644
index 000000000..4e46f307f
--- /dev/null
+++ b/src/renderer/lib/pinnedInsets.test.ts
@@ -0,0 +1,59 @@
+import { describe, it, expect } from 'vitest'
+import { NO_INSETS, insetsForPanels, type RectLike } from './pinnedInsets'
+
+// The canvas wrapper as the placement verbs see it: a 1200×800 box at the window origin.
+const WRAP: RectLike = { left: 0, right: 1200, top: 0, bottom: 800 }
+const rect = (left: number, right: number, top = 54, bottom = 700): RectLike => ({
+ left,
+ right,
+ top,
+ bottom
+})
+
+describe('insetsForPanels', () => {
+ it('is empty for no panels', () => {
+ expect(insetsForPanels(WRAP, [])).toEqual(NO_INSETS)
+ expect(insetsForPanels(WRAP, [null, undefined])).toEqual(NO_INSETS)
+ })
+
+ it('attributes a left-hugging panel to the left edge, up to its far side', () => {
+ // The sessions sidebar: left: 14px, width 300 → clear everything up to x=314.
+ expect(insetsForPanels(WRAP, [rect(14, 314)])).toEqual({ left: 314, right: 0 })
+ })
+
+ it('attributes a right-hugging panel to the right edge', () => {
+ // The explorer drawer: a 360px card against the right edge.
+ expect(insetsForPanels(WRAP, [rect(826, 1186)])).toEqual({ left: 0, right: 374 })
+ })
+
+ it('takes both edges when both panels are pinned', () => {
+ expect(insetsForPanels(WRAP, [rect(14, 314), rect(826, 1186)])).toEqual({
+ left: 314,
+ right: 374
+ })
+ })
+
+ it('keeps the widest panel per edge rather than summing them', () => {
+ expect(insetsForPanels(WRAP, [rect(14, 314), rect(14, 474)])).toEqual({ left: 474, right: 0 })
+ })
+
+ it('ignores a panel that does not overlap the wrapper', () => {
+ // Entirely left of the canvas (a wrapper that does not start at the window edge)…
+ const offset: RectLike = { left: 400, right: 1200, top: 0, bottom: 800 }
+ expect(insetsForPanels(offset, [rect(14, 314)])).toEqual(NO_INSETS)
+ // …and a panel with no vertical overlap at all.
+ expect(insetsForPanels(WRAP, [rect(14, 314, 900, 1200)])).toEqual(NO_INSETS)
+ })
+
+ it('measures from the wrapper edge, not the window, when the wrapper is offset', () => {
+ const offset: RectLike = { left: 100, right: 1200, top: 0, bottom: 800 }
+ // A panel spanning x 14→314 leaves 214px of it over a wrapper that starts at 100.
+ expect(insetsForPanels(offset, [rect(14, 314)])).toEqual({ left: 214, right: 0 })
+ })
+
+ it('never reports more than the wrapper is wide', () => {
+ const wide = insetsForPanels(WRAP, [rect(-500, 5000)])
+ expect(wide.left).toBeLessThanOrEqual(1200)
+ expect(wide.left).toBeGreaterThanOrEqual(0)
+ })
+})
diff --git a/src/renderer/lib/pinnedInsets.ts b/src/renderer/lib/pinnedInsets.ts
new file mode 100644
index 000000000..5568d4d46
--- /dev/null
+++ b/src/renderer/lib/pinnedInsets.ts
@@ -0,0 +1,75 @@
+// Screen-px that PINNED side panels carve out of the canvas wrapper, for the placement verbs
+// (maximize — issue #399; zone snap — issue #394) that would otherwise lay a node out underneath
+// one of them.
+//
+// Only pinned panels count. Unpinned, both the sessions sidebar and the explorer drawer are
+// hover peeks that get out of the way on their own, so a node briefly under one is fine and
+// insetting for it would shrink the canvas for a panel that is about to disappear. Pinning is
+// the user saying "this one stays".
+//
+// Measured rather than derived from the CSS widths: the panels are plain DOM, their widths vary
+// per panel (and per variant), and `uiScale` can change what those widths render as.
+
+/** The parts of a DOMRect this module needs — so callers can pass a real rect or a plain object. */
+export interface RectLike {
+ left: number
+ right: number
+ top: number
+ bottom: number
+}
+
+/** Screen-px to keep clear on each horizontal edge of the canvas wrapper. */
+export interface ScreenInsets {
+ left: number
+ right: number
+}
+
+export const NO_INSETS: ScreenInsets = { left: 0, right: 0 }
+
+/**
+ * How much of `wrap` the given panels cover, per edge. A panel that does not overlap `wrap` at
+ * all contributes nothing; one that does is attributed to whichever edge it hugs, and the whole
+ * edge is inset by it.
+ *
+ * The whole edge, deliberately: both panels are floating cards that cover only part of the
+ * height, but a node is a rectangle. Insetting just the covered band is not expressible, and a
+ * node that starts beside the panel reads as intentional where one sliding under it reads as a
+ * bug.
+ */
+export function insetsForPanels(
+ wrap: RectLike,
+ panels: readonly (RectLike | null | undefined)[]
+): ScreenInsets {
+ let left = 0
+ let right = 0
+ for (const panel of panels) {
+ if (!panel) continue
+ // No overlap on either axis → the panel is not over this wrapper (a different monitor area,
+ // a collapsed 0×0 node, a panel scrolled out of the way).
+ if (panel.right <= wrap.left || panel.left >= wrap.right) continue
+ if (panel.bottom <= wrap.top || panel.top >= wrap.bottom) continue
+ // Attribute to the nearer edge. Both known panels hug one side (sessions left, explorer
+ // right); a panel dead-centre would be a new shape this module should be taught about.
+ const fromLeft = panel.left - wrap.left
+ const fromRight = wrap.right - panel.right
+ if (fromLeft <= fromRight) {
+ left = Math.max(left, Math.min(panel.right - wrap.left, wrap.right - wrap.left))
+ } else {
+ right = Math.max(right, Math.min(wrap.right - panel.left, wrap.right - wrap.left))
+ }
+ }
+ return { left: Math.max(0, left), right: Math.max(0, right) }
+}
+
+/** The panels that dock OVER the canvas while pinned. Both carry a `--pinned` modifier, so the
+ * document alone answers "is it docked right now?" — a hover peek has no such class. */
+const PINNED_PANEL_SELECTOR = '.sessions-sidebar--pinned, .drawer--pinned'
+
+/** `insetsForPanels` against whatever pinned panels are in the document right now. */
+export function measurePinnedInsets(wrap: RectLike): ScreenInsets {
+ if (typeof document === 'undefined') return NO_INSETS
+ const panels = Array.from(document.querySelectorAll(PINNED_PANEL_SELECTOR)).map((el) =>
+ el.getBoundingClientRect()
+ )
+ return insetsForPanels(wrap, panels)
+}
diff --git a/src/renderer/state/workspace.maximize.test.ts b/src/renderer/state/workspace.maximize.test.ts
index 1acb5fe3b..1678ca366 100644
--- a/src/renderer/state/workspace.maximize.test.ts
+++ b/src/renderer/state/workspace.maximize.test.ts
@@ -4,6 +4,7 @@ import {
maximizeNodeToRect,
nodeStatesToFlow,
placeNodeInRect,
+ refitMaximizedNode,
restoreMaximizedNode
} from './workspace'
import type { CanvasNode } from './workspace'
@@ -162,6 +163,58 @@ describe('maximizeTargetRect', () => {
expect(maximizeTargetRect({ x: 0, y: 0, zoom: 1 }, 160, 800, 24)).toBeNull()
expect(maximizeTargetRect({ x: 0, y: 0, zoom: 0 }, 1200, 800, 24)).toBeNull()
})
+
+ it('keeps clear of pinned side panels', () => {
+ // A pinned sessions sidebar (clear to x=314) and a pinned explorer drawer (374 on the right):
+ // the node starts beside the sidebar instead of underneath it.
+ expect(
+ maximizeTargetRect({ x: 0, y: 0, zoom: 1 }, 1200, 800, 24, { left: 314, right: 374 })
+ ).toEqual({
+ x: 24 + 314,
+ y: 24,
+ width: 1200 - 48 - 314 - 374,
+ height: 752
+ })
+ })
+
+ it('counts panel insets toward the refusal floor', () => {
+ // 600px wide with 470px of pinned panels leaves 82px — narrower than a node header.
+ expect(
+ maximizeTargetRect({ x: 0, y: 0, zoom: 1 }, 600, 800, 24, { left: 300, right: 170 })
+ ).toBeNull()
+ })
+})
+
+describe('refitMaximizedNode', () => {
+ const MAXED = { x: 24, y: 24, width: 1152, height: 752 }
+ const NARROWER = { x: 338, y: 24, width: 838, height: 752 }
+
+ it('moves an already maximized node and keeps its restore rect', () => {
+ const maxed = maximizeNodeToRect([term('a', { x: 40, y: 60 })], 'a', MAXED)
+ const refit = refitMaximizedNode(maxed, 'a', NARROWER)
+ const a = refit.find((n) => n.id === 'a')!
+ expect(a.position).toEqual({ x: NARROWER.x, y: NARROWER.y })
+ expect(a.width).toBe(NARROWER.width)
+ // The restore target still points at where the node was BEFORE it was maximized.
+ expect(a.data.premaxRect).toMatchObject({ x: 40, y: 60 })
+ const restored = restoreMaximizedNode(refit, 'a')
+ expect(restored.find((n) => n.id === 'a')!.position).toEqual({ x: 40, y: 60 })
+ })
+
+ it('is idempotent — refitting to the rect it already has returns the same array', () => {
+ const maxed = maximizeNodeToRect([term('a', { x: 40, y: 60 })], 'a', MAXED)
+ // The caller re-measures on every panel change; most land where the node already is, and
+ // those must not mark the workspace dirty.
+ expect(refitMaximizedNode(maxed, 'a', MAXED)).toBe(maxed)
+ expect(refitMaximizedNode(maxed, 'a', NARROWER)).not.toBe(maxed)
+ })
+
+ it('leaves a node that is not maximized alone', () => {
+ // A hand-placed or zone-snapped node is a placement the user owns.
+ const plain = [term('a', { x: 40, y: 60 })]
+ expect(refitMaximizedNode(plain, 'a', NARROWER)).toBe(plain)
+ expect(refitMaximizedNode(plain, 'nope', NARROWER)).toBe(plain)
+ })
})
describe('placeNodeInRect (zone snap, issue #394 v1)', () => {
diff --git a/src/renderer/state/workspace.ts b/src/renderer/state/workspace.ts
index d74256221..20f047c13 100644
--- a/src/renderer/state/workspace.ts
+++ b/src/renderer/state/workspace.ts
@@ -1340,6 +1340,37 @@ function withNodeRect(
* now — and re-fit the ancestor frames back down around it. No-op when the node is missing or
* not maximized.
*/
+/**
+ * Re-fit an ALREADY maximized node to a new frame, keeping its restore rect.
+ *
+ * Maximize is a MODE, not a one-shot placement: while it is on, the node claims the whole usable
+ * canvas. Pinning or unpinning a side panel changes what "whole" means, so the node follows.
+ * A node that is not maximized is left alone — that one was put where it is by hand or by a zone
+ * verb, and those are placements the user owns.
+ */
+export function refitMaximizedNode(
+ nodes: CanvasNode[],
+ nodeId: string,
+ rect: { x: number; y: number; width: number; height: number }
+): CanvasNode[] {
+ const node = nodes.find((n) => n.id === nodeId)
+ const premaxRect = node?.data.premaxRect
+ if (!node || !premaxRect) return nodes
+ // Idempotent: the caller re-measures on every panel change, and most of those land on the rect
+ // the node already has. Returning the same array keeps the workspace out of the dirty/save path
+ // and lets the caller decide by identity whether anything actually moved.
+ const root = rootPosition(node, nodes)
+ if (
+ root.x === rect.x &&
+ root.y === rect.y &&
+ nodeW(node) === rect.width &&
+ nodeH(node) === rect.height
+ ) {
+ return nodes
+ }
+ return withNodeRect(nodes, node, rect, { premaxRect })
+}
+
export function restoreMaximizedNode(nodes: CanvasNode[], nodeId: string): CanvasNode[] {
const node = nodes.find((n) => n.id === nodeId)
const prev = node?.data.premaxRect