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
feat(canvas): a wider grab zone on node resize edges
Ara Babigianda2e0220daab
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex e0618d971..750beb4f7 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -19,6 +19,7 @@ import { useMirrorIdentitySeed } from './useMirrorIdentitySeed'import { useShallow } from 'zustand/react/shallow'import { playSfx, primeSfx } from '@renderer/lib/sfx'import { fanoutStillWorking } from '@renderer/lib/completionAlert'+import { publishCanvasZoom } from '@renderer/lib/canvasZoomVar'import {addEdge,applyEdgeChanges,@@ -32,6 +33,7 @@ import {useEdgesState,useNodesState,useReactFlow,+ useStoreApi,type Connection,type EdgeChange,type Viewport@@ -1966,6 +1968,10 @@ export function Canvas() {getNodesBounds} = useReactFlow()+ // `--nt-zoom` on React Flow's root: the resize grab zones size themselves in screen px with it.+ const rfStore = useStoreApi()+ useEffect(() => publishCanvasZoom(rfStore), [rfStore])+// Single "fit everything" path for every fit-view entry point (dock button, the built-in// Controls button, the ⌘K palette and the context menu) so they behave identically and there's// one place to tune. Solved per click against the CURRENT chrome layout and the CURRENT contentdiff --git a/src/renderer/lib/canvasZoomVar.test.ts b/src/renderer/lib/canvasZoomVar.test.tsnew file mode 100644index 000000000..8e7f2ffa7--- /dev/null+++ b/src/renderer/lib/canvasZoomVar.test.ts@@ -0,0 +1,58 @@+import { afterEach, describe, expect, it, vi } from 'vitest'+import { publishCanvasZoom, ZOOM_SETTLE_MS } from './canvasZoomVar'++type State = { transform: readonly [number, number, number]; domNode?: Element | null }++const fakeStore = (zoom: number, domNode: Element | null) => {+ let state: State = { transform: [0, 0, zoom], domNode }+ const listeners = new Set<(s: State) => void>()+ return {+ getState: () => state,+ subscribe: (fn: (s: State) => void) => {+ listeners.add(fn)+ return () => listeners.delete(fn)+ },+ set: (patch: Partial<State>) => {+ state = { ...state, ...patch }+ listeners.forEach((fn) => fn(state))+ }+ }+}++const fakeEl = () => {+ const writes: string[] = []+ return { writes, el: { style: { setProperty: (_k: string, v: string) => writes.push(v) } } as unknown as Element }+}++describe('publishCanvasZoom', () => {+ afterEach(() => vi.useRealTimers())++ it("writes onto React Flow's root at once, then only once a zoom gesture settles", () => {+ vi.useFakeTimers()+ const store = fakeStore(1, null)+ const { el, writes } = fakeEl()+ const stop = publishCanvasZoom(store)+ expect(writes).toEqual([]) // no root yet — nothing written, nothing on <html>+ store.set({ domNode: el })+ expect(writes).toEqual(['1']) // the root's first value is immediate+ store.set({ transform: [50, 0, 1] }) // a pan writes nothing+ // a zoom gesture: many frames, one write after the last+ for (const z of [0.9, 0.8, 0.7, 0.6]) {+ store.set({ transform: [0, 0, z] })+ vi.advanceTimersByTime(ZOOM_SETTLE_MS / 3)+ }+ expect(writes).toEqual(['1'])+ vi.advanceTimersByTime(ZOOM_SETTLE_MS)+ expect(writes).toEqual(['1', '0.6'])+ // a programmatic fitView / setViewport is one change, settled the same way+ store.set({ transform: [10, 10, 1.25] })+ vi.advanceTimersByTime(ZOOM_SETTLE_MS)+ expect(writes).toEqual(['1', '0.6', '1.25'])+ store.set({ transform: [0, 0, 0] }) // a degenerate zoom is ignored+ vi.advanceTimersByTime(ZOOM_SETTLE_MS)+ stop()+ store.set({ transform: [0, 0, 2] })+ vi.advanceTimersByTime(ZOOM_SETTLE_MS)+ expect(writes).toEqual(['1', '0.6', '1.25'])+ })+})diff --git a/src/renderer/lib/canvasZoomVar.ts b/src/renderer/lib/canvasZoomVar.tsnew file mode 100644index 000000000..d184125dc--- /dev/null+++ b/src/renderer/lib/canvasZoomVar.ts@@ -0,0 +1,53 @@+// React Flow's zoom, published as the `--nt-zoom` custom property so CSS inside the zoomed+// viewport can size something in SCREEN px (`calc(8px / var(--nt-zoom))`) — the node resize grab+// zones, which must stay a comfortable target at every zoom. Read from the store subscription, not+// `onMove`, so a programmatic setViewport / fitView is covered too. Written on React Flow's own+// root (`domNode`), never the document, and only once the zoom SETTLES: a custom property change+// restyles every element under it, and a zoom gesture is a stream of frames — so mid-gesture the+// zones keep the previous zoom's size and are exact again `ZOOM_SETTLE_MS` after the last frame.+// The first value (and a new root element) is written at once. A pan writes nothing.++export const ZOOM_SETTLE_MS = 150++interface ZoomState {+ transform: readonly [number, number, number]+ domNode?: Element | null+}+interface ZoomSource {+ getState(): ZoomState+ subscribe(listener: (state: ZoomState) => void): () => void+}++export function publishCanvasZoom(store: ZoomSource): () => void {+ let lastZoom = NaN+ let lastEl: Element | null = null+ let timer: ReturnType<typeof setTimeout> | null = null+ const write = (): void => {+ timer = null+ const s = store.getState()+ const zoom = s.transform[2]+ const el = s.domNode ?? null+ if (!el || !(zoom > 0) || (zoom === lastZoom && el === lastEl)) return+ lastZoom = zoom+ lastEl = el+ ;(el as HTMLElement).style.setProperty('--nt-zoom', String(zoom))+ }+ const onChange = (s: ZoomState): void => {+ const el = s.domNode ?? null+ if (el && el !== lastEl) {+ // first publish onto this root: no reason to wait+ if (timer) clearTimeout(timer)+ write()+ return+ }+ if (s.transform[2] === lastZoom) return // a pan, or a zoom that came back+ if (timer) clearTimeout(timer)+ timer = setTimeout(write, ZOOM_SETTLE_MS)+ }+ onChange(store.getState())+ const unsubscribe = store.subscribe(onChange)+ return () => {+ unsubscribe()+ if (timer) clearTimeout(timer)+ }+}diff --git a/src/renderer/styles.css b/src/renderer/styles.cssindex c9729dcf1..ad88c4c06 100644--- a/src/renderer/styles.css+++ b/src/renderer/styles.css@@ -7478,12 +7478,91 @@ body,pointer-events: auto;}+/* ---- Resize grab zones -------------------------------------------------------------------------+ React Flow's resize lines are 1px and its corner handles 5px, so the resize cursor appeared only+ on a hairline. Each control gets an invisible ::before hit region (the cursor and the press both+ belong to the control); the visible line and handle are unchanged. HIG pointing-devices.md ›+ "Add padding around interactive elements to create comfortable hit regions" — 12pt for an element+ with a visible edge — and accessibility.md: desktop targets 20x20pt minimum, which the corners get.+ - Edges: 12 screen px, biased OUTWARD (8 outside the border, 4 inside — and never more than 6+ flow px inside), so the band takes as little as possible from header buttons and text.+ - Corners: 20x20 screen px (14 outside, 6 inside, inner capped at 6 flow px), drawn after the lines so a corner wins where+ they overlap, and covering the whole band intersection, so sliding along the border never+ drops to the default cursor (HIG: contiguous hit regions).+ - Sized in SCREEN px through `--nt-zoom` (lib/canvasZoomVar.ts); below zoom 0.3 the zone shrinks+ with the node instead of swallowing a tiny one.+ Exists only while the resizer renders, i.e. while the node is selected. */+:root {+ --nt-zoom: 1;+}+.react-flow__resize-control {+ --rz-k: max(var(--nt-zoom), 0.3);+ --rz-out: calc(8px / var(--rz-k));+ /* The INNER part is also capped in flow px (6): zoomed out, 4 screen px is a big slice of a+ small node's header — its drag area and its close/maximize buttons. */+ --rz-in: min(calc(4px / var(--rz-k)), 6px);+ /* Corner handles are already counter-scaled by React Flow (`scale: max(1/zoom, 1)`), so below+ zoom 1 their flow px ARE screen px; only above it does the size need dividing. */+ --rc-k: max(var(--nt-zoom), 1);+ --rc-out: calc(14px / var(--rc-k));+ /* Inner part: 6 screen px, at most 6 flow px (below zoom 1 the handle's own scale is 1/zoom). */+ --rc-in: calc(6px * min(var(--nt-zoom), 1) / var(--rc-k));+}/* The node's resize controls are a SIBLING of its root (so a glass root's backdrop-filter cannotclip them), which puts the later-painted root over their inner half. Lift them above the rootand the terminal's hover guard (z 2); the kanban half-pill stays above them. */.react-flow__node > .react-flow__resize-control {z-index: 3;}+.react-flow__resize-control::before {+ content: '';+ position: absolute;+}+.react-flow__resize-control.line.left::before {+ top: 0;+ bottom: 0;+ left: calc(-1 * var(--rz-out));+ right: calc(-1 * var(--rz-in));+}+.react-flow__resize-control.line.right::before {+ top: 0;+ bottom: 0;+ right: calc(-1 * var(--rz-out));+ left: calc(-1 * var(--rz-in));+}+.react-flow__resize-control.line.top::before {+ left: 0;+ right: 0;+ top: calc(-1 * var(--rz-out));+ bottom: calc(-1 * var(--rz-in));+}+.react-flow__resize-control.line.bottom::before {+ left: 0;+ right: 0;+ bottom: calc(-1 * var(--rz-out));+ top: calc(-1 * var(--rz-in));+}+/* A handle's padding box is 5px, centred on the corner: offsets are from that centre. */+.react-flow__resize-control.handle::before {+ width: calc(var(--rc-out) + var(--rc-in));+ height: calc(var(--rc-out) + var(--rc-in));+}+.react-flow__resize-control.handle.left::before {+ left: calc(2.5px - var(--rc-out));+}+.react-flow__resize-control.handle.right::before {+ left: calc(2.5px - var(--rc-in));+}+.react-flow__resize-control.handle.top::before {+ top: calc(2.5px - var(--rc-out));+}+.react-flow__resize-control.handle.bottom::before {+ top: calc(2.5px - var(--rc-in));+}+/* The paint-only copies (`.nt-resize-ghost`) carry no grab zone. */+.react-flow__resize-control.nt-resize-ghost::before {+ content: none;+}/* Bound to a git worktree: a checkout, not a loose grouping. Solid, thicker border (the tint isbumped inline from the group's own data.color — no separate palette) so it reads as bound fromdiff --git a/src/renderer/styles.resize-grab.test.ts b/src/renderer/styles.resize-grab.test.tsnew file mode 100644index 000000000..ecda1abda--- /dev/null+++ b/src/renderer/styles.resize-grab.test.ts@@ -0,0 +1,77 @@+import { readFileSync } from 'node:fs'+import { join } from 'node:path'+import { describe, expect, it } from 'vitest'++/**+ * Node resize grab zones: an invisible ::before on every React Flow resize control widens the hit+ * region (edges 12 screen px, biased outward; corners 20x20) while the visible line stays 1px.+ * Parsed from the real stylesheet so a rule that loses its outward bias or its screen-px sizing+ * goes red. The live half (elementFromPoint around a selected node) is a dev-build probe.+ */+const CSS = readFileSync(join(__dirname, 'styles.css'), 'utf8').replace(/\r\n/g, '\n')+const rules = new Map<string, string>()+const rootBodies: string[] = []+{+ const noComments = CSS.replace(/\/\*[\s\S]*?\*\//g, '')+ const re = /([^{}]+)\{([^{}]*)\}/g+ let m: RegExpExecArray | null+ while ((m = re.exec(noComments))) {+ const sel = m[1].replace(/\s+/g, ' ').trim()+ rules.set(sel, m[2])+ if (sel === ':root') rootBodies.push(m[2])+ }+}+/** The screen-px number a zone var is built from (`calc(Npx / k)`, possibly wrapped in a cap). */+const px = (body: string, name: string): number => {+ const m = body.match(new RegExp(`${name}:[^;]*?calc\\((\\d+)px\\s*[/*]`))+ return m ? Number(m[1]) : NaN+}++describe('resize grab zones', () => {+ const vars = rules.get('.react-flow__resize-control') ?? ''++ it('sizes the zones in screen px through --nt-zoom', () => {+ expect(vars).toMatch(/--rz-k:\s*max\(var\(--nt-zoom\),\s*0\.3\)/)+ // corner handles are counter-scaled by React Flow below zoom 1, so they divide only above it+ expect(vars).toMatch(/--rc-k:\s*max\(var\(--nt-zoom\),\s*1\)/)+ expect(vars).toMatch(/--rc-out:\s*calc\(14px \/ var\(--rc-k\)\)/)+ expect(rootBodies.some((b) => /--nt-zoom:\s*1;/.test(b))).toBe(true)+ })++ it('caps the INNER extents at 6 flow px, so zooming out never buries header buttons', () => {+ expect(vars).toMatch(/--rz-in:\s*min\(calc\(4px \/ var\(--rz-k\)\),\s*6px\)/)+ expect(vars).toMatch(/--rc-in:\s*calc\(6px \* min\(var\(--nt-zoom\),\s*1\) \/ var\(--rc-k\)\)/)+ })++ it('edges are a 12px band biased outward; corners at least 20x20 and cover the band', () => {+ const out = px(vars, '--rz-out')+ const inn = px(vars, '--rz-in')+ const cOut = px(vars, '--rc-out')+ const cIn = px(vars, '--rc-in')+ expect(out + inn).toBe(12)+ expect(out).toBeGreaterThan(inn)+ expect(cOut + cIn).toBeGreaterThanOrEqual(20)+ expect(cOut).toBeGreaterThanOrEqual(out)+ expect(cIn).toBeGreaterThanOrEqual(inn)+ })++ it('every side extends outward by --rz-out and inward by --rz-in', () => {+ const sides: Record<string, [string, string]> = { left: ['left', 'right'], right: ['right', 'left'], top: ['top', 'bottom'], bottom: ['bottom', 'top'] }+ for (const [side, [outer, inner]] of Object.entries(sides)) {+ const body = rules.get(`.react-flow__resize-control.line.${side}::before`) ?? ''+ expect(body).toMatch(new RegExp(`(^|\\s)${outer}:\\s*calc\\(-1 \\* var\\(--rz-out\\)\\)`))+ expect(body).toMatch(new RegExp(`(^|\\s)${inner}:\\s*calc\\(-1 \\* var\\(--rz-in\\)\\)`))+ }+ expect(rules.get('.react-flow__resize-control::before')).toMatch(/content:\s*''/)+ })++ it('is invisible: no grab-zone rule paints anything', () => {+ const zones = [...rules].filter(([sel]) => sel.includes('.react-flow__resize-control') && sel.includes('::before'))+ expect(zones.length).toBeGreaterThanOrEqual(9)+ for (const [, body] of zones) expect(body).not.toMatch(/background|border|box-shadow|outline|opacity/)+ })++ it('the paint-only resizer copies (.nt-resize-ghost) grow no grab zone', () => {+ expect(rules.get('.react-flow__resize-control.nt-resize-ghost::before')).toMatch(/content:\s*none/)+ })+})