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: zoom presets in the dock
Bas Milius2644b0192297
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex 236cbbf64..519ef4022 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -152,7 +152,9 @@ import { transferConversationItems } from '../lib/transferItems'import { reopenVariants } from '../lib/reopenVariants'import { modelsForAgent } from '@shared/agents/model-gateway'import { useModelGateway } from '../state/modelGateway'-import { viewportAtZoom1 } from '../lib/zoomReset'+import { viewportAtZoom } from '../lib/zoomReset'+import { zoomFromPct } from '../lib/zoomPresets'+import { CANVAS_MAX_ZOOM, CANVAS_MIN_ZOOM } from './zoom-limits'import { isSpaceRelease, spacePanKeydown } from '../lib/spacePan'import {FLOW_NODE_CLASS,@@ -1323,16 +1325,24 @@ export function Canvas() {* The anchor is the viewport CENTRE rather than the origin: zooming about the corner throws the* user's work off screen, which is what makes a reset feel like a jump rather than a correction.*/- const zoomTo100 = useCallback(() => {- const wrap = flowWrapRef.current- const current = getViewport()- const next = viewportAtZoom1(current, {- x: (wrap?.clientWidth ?? 0) / 2,- y: (wrap?.clientHeight ?? 0) / 2- })- if (next === current) return- void setViewport(next, { duration: 200 })- }, [getViewport, setViewport])+ const zoomToScale = useCallback(+ (target: number) => {+ const wrap = flowWrapRef.current+ const current = getViewport()+ const next = viewportAtZoom(current, {+ x: (wrap?.clientWidth ?? 0) / 2,+ y: (wrap?.clientHeight ?? 0) / 2+ }, target)+ if (next === current) return+ void setViewport(next, { duration: 200 })+ },+ [getViewport, setViewport]+ )++ const zoomTo100 = useCallback(() => zoomToScale(1), [zoomToScale])++ /** The dock's preset menu: an exact percentage, centre-anchored like every other zoom command. */+ const zoomToPct = useCallback((pct: number) => zoomToScale(zoomFromPct(pct)), [zoomToScale])const activeProjectId = useProjects((s) => s.activeProjectId)// Project-level worktree defaults (basePath/baseRef) for the active project, read from the warmed@@ -11491,8 +11501,8 @@ export function Canvas() {onNodeContextMenu={onNodeContextMenu}onSelectionContextMenu={onSelectionContextMenu}onNodeDoubleClick={onNodeDoubleClick}- minZoom={0.01}- maxZoom={2}+ minZoom={CANVAS_MIN_ZOOM}+ maxZoom={CANVAS_MAX_ZOOM}proOptions={{ hideAttribution: true }}deleteKeyCode={null}// 'pan' drag mode (Miro-style, opt-in): left-drag on empty canvas pans (React Flow@@ -12103,6 +12113,7 @@ export function Canvas() {onFitView={fitAll}onZoomIn={() => zoomIn({ duration: 150 })}onZoomOut={() => zoomOut({ duration: 150 })}+ onZoomTo={zoomToPct}onDictate={toggleDictation}dictateActive={dictationOpen}/>diff --git a/src/renderer/canvas/wheel-zoom.ts b/src/renderer/canvas/wheel-zoom.tsindex 1b8e4605f..11de85eea 100644--- a/src/renderer/canvas/wheel-zoom.ts+++ b/src/renderer/canvas/wheel-zoom.ts@@ -19,6 +19,8 @@* second, far beyond any physical pinch.*/+import { CANVAS_MAX_ZOOM, CANVAS_MIN_ZOOM } from './zoom-limits'+/** One burst's total influence on zoom, in deltaY pixels — the historical per-event cap. */export const WHEEL_ZOOM_MAX_STEP = 50@@ -26,10 +28,6 @@ export const WHEEL_ZOOM_MAX_STEP = 50* deliberate successive clicks are never merged. */const BURST_WINDOW_MS = 40-/** Mirrors the <ReactFlow minZoom/maxZoom> props in Canvas.tsx — keep in sync. */-const MIN_ZOOM = 0.01-const MAX_ZOOM = 2-const ZOOM_STEP_RATE = 0.01export class WheelZoomBurstLimiter {@@ -53,7 +51,10 @@ export class WheelZoomBurstLimiter {/** The zoom the canvas moves to for an (already limited) wheel step at a given speed. */export const nextWheelZoom = (zoom: number, deltaY: number, speed: number): number =>- Math.min(MAX_ZOOM, Math.max(MIN_ZOOM, zoom * Math.exp(-deltaY * ZOOM_STEP_RATE * speed)))+ Math.min(+ CANVAS_MAX_ZOOM,+ Math.max(CANVAS_MIN_ZOOM, zoom * Math.exp(-deltaY * ZOOM_STEP_RATE * speed))+ )/** settings.json is hand-editable, so the multiplier is validated at point of use (same* convention as tmux scrollback): non-numbers fall back to 1, numbers clamp to the slider'sdiff --git a/src/renderer/canvas/zoom-limits.ts b/src/renderer/canvas/zoom-limits.tsnew file mode 100644index 000000000..6543c0436--- /dev/null+++ b/src/renderer/canvas/zoom-limits.ts@@ -0,0 +1,10 @@+/**+ * The canvas zoom range, in ONE place.+ *+ * These are the `<ReactFlow minZoom/maxZoom>` props, the wheel-step clamp and the ceiling every+ * zoom preset is measured against. They used to be a private copy in `wheel-zoom.ts` carrying a+ * "keep in sync with Canvas.tsx" comment; a third reader (the dock's preset menu, which must not+ * offer a zoom React Flow would silently clamp) is exactly the drift that comment predicted.+ */+export const CANVAS_MIN_ZOOM = 0.01+export const CANVAS_MAX_ZOOM = 2diff --git a/src/renderer/components/Dock.tsx b/src/renderer/components/Dock.tsxindex ff2f909c8..a05f6ed07 100644--- a/src/renderer/components/Dock.tsx+++ b/src/renderer/components/Dock.tsx@@ -9,6 +9,7 @@ import { useSettings } from '../state/settings'import { useProjects } from '../state/projects'import { accountsForProject, sshAccountsHint } from '../state/workspace'import { CONTENT_ADD_ITEMS, contentAddItemsToDockRows, type AddHandlers } from '../lib/addMenuSpec'+import { ZOOM_PRESETS, activeZoomPreset } from '../lib/zoomPresets'const isMac = /Mac/i.test(navigator.platform || navigator.userAgent)@@ -42,6 +43,8 @@ interface DockProps {onFitView: () => voidonZoomIn: () => voidonZoomOut: () => void+ /** Jump to an exact zoom (a preset percentage), holding the screen centre still. */+ onZoomTo: (pct: number) => voidonDictate: () => voiddictateActive: boolean}@@ -77,10 +80,12 @@ export function Dock({onFitView,onZoomIn,onZoomOut,+ onZoomTo,onDictate,dictateActive}: DockProps) {const [menuOpen, setMenuOpen] = useState(false)+ const [zoomMenuOpen, setZoomMenuOpen] = useState(false)// Which builtin's flyout submenu is open (at most one). A builtin earns a flyout only when it has// ≥1 inheriting custom agent (one with a `baseAgent` matching it); otherwise it stays a flat// button, byte-identical to before this nesting existed.@@ -128,6 +133,14 @@ export function Dock({setMenuOpen(false)}+ const pickZoom = (fn: () => void) => () => {+ fn()+ setZoomMenuOpen(false)+ }++ // The preset the readout currently sits on, or null between two — the menu's tick.+ const activePreset = activeZoomPreset(zoomPct)+// Derive the content rows from the shared add-menu spec (the same list the pane right-click and// the sidebar "+" use), so the Dock can no longer lag the canvas menu on which kinds are addable.// Terminal + agents + "New Remote Connection" stay Dock-local (agents have bespoke flyouts;@@ -153,7 +166,15 @@ export function Dock({return (<>- {menuOpen && <div className="dock-backdrop" onClick={() => setMenuOpen(false)} />}+ {(menuOpen || zoomMenuOpen) && (+ <div+ className="dock-backdrop"+ onClick={() => {+ setMenuOpen(false)+ setZoomMenuOpen(false)+ }}+ />+ )}<div className="dock">{menuOpen && (@@ -285,7 +306,10 @@ export function Dock({<buttonclassName={`dock-btn dock-add${menuOpen ? ' active' : ''}`}title="Add node"- onClick={() => setMenuOpen((v) => !v)}+ onClick={() => {+ setZoomMenuOpen(false)+ setMenuOpen((v) => !v)+ }}><PlusIcon /></button>@@ -347,7 +371,41 @@ export function Dock({<button className="dock-btn dock-zoom-btn" title="Zoom out" onClick={onZoomOut}><MinusIcon /></button>- <span className="dock-zoom">{zoomPct}%</span>+ <div className="dock-zoom-wrap">+ {zoomMenuOpen && (+ <div className="dock-menu dock-zoom-menu">+ {ZOOM_PRESETS.map((pct) => (+ <button+ key={pct}+ className={pct === activePreset ? 'is-current' : undefined}+ onClick={pickZoom(() => onZoomTo(pct))}+ >+ <span className="dock-menu__check">{pct === activePreset ? <CheckIcon /> : null}</span>+ <span>{pct}%</span>+ {pct === 100 && <span className="dock-menu__chord">{isMac ? '⌘0' : 'Ctrl+0'}</span>}+ </button>+ ))}+ <span className="dock-menu__rule" />+ <button onClick={pickZoom(onFitView)}>+ <span className="dock-menu__check" />+ <span>Zoom to fit</span>+ <span className="dock-menu__chord">⇧1</span>+ </button>+ </div>+ )}+ <button+ className={`dock-zoom${zoomMenuOpen ? ' active' : ''}`}+ title="Zoom presets"+ aria-haspopup="menu"+ aria-expanded={zoomMenuOpen}+ onClick={() => {+ setMenuOpen(false)+ setZoomMenuOpen((v) => !v)+ }}+ >+ {zoomPct}%+ </button>+ </div><button className="dock-btn dock-zoom-btn" title="Zoom in" onClick={onZoomIn}><PlusSmallIcon /></button>@@ -401,6 +459,13 @@ function PlusSmallIcon() {</svg>)}+function CheckIcon() {+ return (+ <svg {...S} width={13} height={13} strokeWidth={2.4}>+ <path d="M5 12.5l4.5 4.5L19 7.5" />+ </svg>+ )+}function MinusIcon() {return (<svg {...S} width={15} height={15}>diff --git a/src/renderer/lib/zoomPresets.test.ts b/src/renderer/lib/zoomPresets.test.tsnew file mode 100644index 000000000..2da40971a--- /dev/null+++ b/src/renderer/lib/zoomPresets.test.ts@@ -0,0 +1,40 @@+import { describe, expect, it } from 'vitest'+import { CANVAS_MAX_ZOOM, CANVAS_MIN_ZOOM } from '../canvas/zoom-limits'+import { ZOOM_PRESETS, activeZoomPreset, isOfferableZoomPct, zoomFromPct } from './zoomPresets'++describe('zoom presets', () => {+ it('offers 100% — the whole point of the menu', () => {+ expect(ZOOM_PRESETS).toContain(100)+ })++ it('never offers a zoom React Flow would silently clamp', () => {+ // A row that lands somewhere other than its own label is worse than no row at all.+ for (const pct of ZOOM_PRESETS) {+ expect(isOfferableZoomPct(pct)).toBe(true)+ expect(zoomFromPct(pct)).toBeGreaterThanOrEqual(CANVAS_MIN_ZOOM)+ expect(zoomFromPct(pct)).toBeLessThanOrEqual(CANVAS_MAX_ZOOM)+ }+ })++ it('is ordered, so the menu reads as a scale', () => {+ expect([...ZOOM_PRESETS]).toEqual([...ZOOM_PRESETS].sort((a, b) => a - b))+ })+})++describe('activeZoomPreset', () => {+ it('ticks the preset the readout is showing', () => {+ expect(activeZoomPreset(100)).toBe(100)+ expect(activeZoomPreset(50)).toBe(50)+ })++ it('ticks on the ROUNDED percentage the dock displays, not the raw zoom', () => {+ // At 99.6% the dock already says "100%"; ticking nothing there reads as a broken menu.+ expect(activeZoomPreset(99.6)).toBe(100)+ expect(activeZoomPreset(100.4)).toBe(100)+ })++ it('ticks nothing between two presets', () => {+ expect(activeZoomPreset(112)).toBeNull()+ expect(activeZoomPreset(3)).toBeNull()+ })+})diff --git a/src/renderer/lib/zoomPresets.ts b/src/renderer/lib/zoomPresets.tsnew file mode 100644index 000000000..301743e58--- /dev/null+++ b/src/renderer/lib/zoomPresets.ts@@ -0,0 +1,34 @@+import { CANVAS_MAX_ZOOM, CANVAS_MIN_ZOOM } from '../canvas/zoom-limits'++/**+ * The zoom presets behind the dock's percentage readout.+ *+ * Before this the readout was inert text between two step buttons: getting back to 100% meant+ * clicking `+`/`−` until the number happened to land on it, and it rarely did — the wheel and the+ * step buttons both move zoom multiplicatively, so the reachable set from an arbitrary zoom+ * contains no round number at all. `Fit view` was the only one-click camera command, and it lands+ * on whatever the content bounds imply, never on 1.+ *+ * The list is deliberately bounded by the canvas's own range: `CANVAS_MAX_ZOOM` is 2, so 200% is+ * the last entry — a preset React Flow would silently clamp is a menu row that lies about what it+ * does.+ */+export const ZOOM_PRESETS = [25, 50, 75, 100, 150, 200] as const++/** A preset percentage as React Flow's scale factor. */+export const zoomFromPct = (pct: number): number => pct / 100++/** Whether `pct` is offerable at all — the guard the list itself is built to satisfy. */+export const isOfferableZoomPct = (pct: number): boolean =>+ zoomFromPct(pct) >= CANVAS_MIN_ZOOM && zoomFromPct(pct) <= CANVAS_MAX_ZOOM++/**+ * Which preset the dock should tick, or `null` when the camera sits between two.+ *+ * The comparison is on the ROUNDED percentage the dock already displays, not on the raw zoom: at+ * 0.999 the readout says 100% and a menu that ticked nothing there would read as broken. Rounding+ * is the display's contract, so the tick has to share it rather than re-derive a tolerance.+ */+export function activeZoomPreset(zoomPct: number): number | null {+ return ZOOM_PRESETS.find((p) => p === Math.round(zoomPct)) ?? null+}diff --git a/src/renderer/lib/zoomReset.test.ts b/src/renderer/lib/zoomReset.test.tsindex fbb799510..8c1711805 100644--- a/src/renderer/lib/zoomReset.test.ts+++ b/src/renderer/lib/zoomReset.test.ts@@ -1,5 +1,5 @@import { describe, expect, it } from 'vitest'-import { viewportAtZoom1 } from './zoomReset'+import { viewportAtZoom, viewportAtZoom1 } from './zoomReset'const CENTRE = { x: 600, y: 400 }@@ -37,3 +37,38 @@ describe('viewportAtZoom1', () => {expect(viewportAtZoom1({ x: 100, y: 100, zoom: 2 }, CENTRE).zoom).toBe(1)})})++describe('viewportAtZoom', () => {+ const worldAt = (v: { x: number; y: number; zoom: number }, s: { x: number; y: number }) => ({+ x: (s.x - v.x) / v.zoom,+ y: (s.y - v.y) / v.zoom+ })++ it('lands on the requested zoom, holding the screen CENTRE still', () => {+ const before = { x: -4194.86, y: -1090.16, zoom: 0.976135 }+ const after = viewportAtZoom(before, CENTRE, 0.5)+ expect(after.zoom).toBe(0.5)+ expect(worldAt(after, CENTRE).x).toBeCloseTo(worldAt(before, CENTRE).x, 6)+ expect(worldAt(after, CENTRE).y).toBeCloseTo(worldAt(before, CENTRE).y, 6)+ })++ it('holds the centre when zooming IN too — the direction the *1 wrapper never exercises', () => {+ const before = { x: -300, y: -120, zoom: 0.75 }+ const after = viewportAtZoom(before, CENTRE, 2)+ expect(after.zoom).toBe(2)+ expect(worldAt(after, CENTRE).x).toBeCloseTo(worldAt(before, CENTRE).x, 6)+ expect(worldAt(after, CENTRE).y).toBeCloseTo(worldAt(before, CENTRE).y, 6)+ })++ it('returns the SAME object when already at the target, so the caller skips the animation', () => {+ const v = { x: 10, y: 20, zoom: 0.5 }+ expect(viewportAtZoom(v, CENTRE, 0.5)).toBe(v)+ })++ it('refuses an unusable TARGET rather than producing NaN', () => {+ const v = { x: 10, y: 20, zoom: 0.5 }+ for (const target of [0, -1, NaN, Infinity]) {+ expect(viewportAtZoom(v, CENTRE, target)).toBe(v)+ }+ })+})diff --git a/src/renderer/lib/zoomReset.ts b/src/renderer/lib/zoomReset.tsindex 4eaea2d1b..0eb34cf6b 100644--- a/src/renderer/lib/zoomReset.ts+++ b/src/renderer/lib/zoomReset.ts@@ -6,24 +6,36 @@ export interface Viewport {}/**- * The viewport that puts the canvas back at 100% without moving what the user is looking at.+ * The viewport that holds the screen centre still while moving to `target` zoom.** The anchor is the viewport CENTRE, not the origin: zooming about the corner throws the user's- * work off screen, which makes a reset feel like a jump rather than a correction.+ * work off screen, which makes a jump to a chosen zoom feel like a teleport rather than a change+ * of scale.** Zoom 1 matters beyond ergonomics — it is the only ratio at which the shared renderer samples the* glyph atlas texel-for-texel, so "am I actually at 1?" is a question both users and bug reports* need to be able to settle. Until this existed the only way was to read the viewport transform in* DevTools, which is how the 2026-08-09 crispness report was finally pinned (at 0.976).*- * A zoom that is already 1, or one that is not a usable number, returns the viewport UNCHANGED —- * the command is then a no-op rather than a nudge.+ * A zoom that already equals the target, or either side not being a usable number, returns the+ * viewport UNCHANGED — the command is then a no-op rather than a nudge. Callers rely on the+ * IDENTITY of that return to skip the animated `setViewport` entirely.*/-export function viewportAtZoom1(current: Viewport, centre: { x: number; y: number }): Viewport {+export function viewportAtZoom(+ current: Viewport,+ centre: { x: number; y: number },+ target: number+): Viewport {const { x, y, zoom } = current- if (!Number.isFinite(zoom) || zoom <= 0 || zoom === 1) return current+ if (!Number.isFinite(target) || target <= 0) return current+ if (!Number.isFinite(zoom) || zoom <= 0 || zoom === target) return current// The world point under the screen centre, held fixed across the change.const worldX = (centre.x - x) / zoomconst worldY = (centre.y - y) / zoom- return { x: centre.x - worldX, y: centre.y - worldY, zoom: 1 }+ return { x: centre.x - worldX * target, y: centre.y - worldY * target, zoom: target }+}++/** `viewportAtZoom` at 100% — the "actual size" reset behind ⌘/Ctrl+0. */+export function viewportAtZoom1(current: Viewport, centre: { x: number; y: number }): Viewport {+ return viewportAtZoom(current, centre, 1)}diff --git a/src/renderer/styles.css b/src/renderer/styles.cssindex 7859f558e..70c78ea1f 100644--- a/src/renderer/styles.css+++ b/src/renderer/styles.css@@ -585,12 +585,78 @@ body,height: 30px;}+.dock-zoom-wrap {+ position: relative;+ display: inline-flex;+}+.dock-zoom {- min-width: 46px;+ min-width: 52px;+ padding: 5px 6px;text-align: center;font-size: 12px;+ font-variant-numeric: tabular-nums;color: var(--muted);+ background: transparent;+ border: none;+ border-radius: 8px;user-select: none;+ cursor: pointer;+}++.dock-zoom:hover {+ background: var(--panel-header);+ color: var(--text);+}++.dock-zoom.active {+ background: var(--panel-header);+ color: var(--text);+}++/* Zoom presets, anchored to the readout instead of the dock's left edge like the add-menu. */+.dock-zoom-menu {+ left: 50%;+ transform: translateX(-50%);+ min-width: 168px;+}++.dock-zoom-menu button {+ gap: 8px;+ padding: 7px 10px;+ font-variant-numeric: tabular-nums;+}++/* The generic `.dock-menu svg` rule paints every menu glyph muted; the tick is a state marker,+ not a leading icon, so it keeps the accent that says "this is where you are". */+.dock-zoom-menu .dock-menu__check svg {+ color: inherit;+}++.dock-zoom-menu button.is-current {+ color: var(--accent);+}++.dock-menu__check {+ display: inline-flex;+ align-items: center;+ justify-content: center;+ width: 13px;+ flex-shrink: 0;+ color: var(--accent);+}++.dock-menu__chord {+ margin-left: auto;+ padding-left: 12px;+ font-size: 11px;+ color: var(--muted);+}++.dock-menu__rule {+ height: 1px;+ margin: 4px 6px;+ background: var(--border);}.dock-dirty {