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): per-burst wheel-zoom cap + zoom speed setting
Rick-VIPERe98333c35fcb
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex 49f76fb64..7ab7da557 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -35,6 +35,7 @@ import {} from '../nodes/TerminalNode'import { solveFitPadding } from './fit-view'import { MacWheelGestureRouter, trackpadRoutingEnabled } from './wheel-gesture'+import { WheelZoomBurstLimiter, clampWheelZoomSpeed, nextWheelZoom } from './wheel-zoom'import { selectedLocalFilePaths } from './canvas-file-copy'import {canvasImagePasteArmedAfterKey,@@ -3034,6 +3035,7 @@ export function Canvas() {// MacWheelGestureRouter tells them apart (and stays sticky for the length of one physical// gesture) and hands trackpad packets back to React Flow's own panOnScroll.const wheelZoom = settings.wheelZoom+ const wheelZoomSpeed = clampWheelZoomSpeed(settings.wheelZoomSpeed)// The escape hatch, resolved ONCE: the router and React Flow's panOnScroll below must agree, or// a gesture neither of them pans is a gesture that does nothing.const trackpadRouting = trackpadRoutingEnabled(isMac, settings.trackpadPan)@@ -3041,9 +3043,11 @@ export function Canvas() {const wrap = flowWrapRef.currentif (!wrap) returnconst wheelRouting = new MacWheelGestureRouter()+ const wheelLimiter = new WheelZoomBurstLimiter()const onWheel = (e: WheelEvent) => {if (canvasLocked) return- if (!e.ctrlKey && !e.metaKey) {+ const plainWheel = !e.ctrlKey && !e.metaKey+ if (plainWheel) {// The ancestor walk is the expensive part of this handler at ~120 Hz, so it is memoized// per packet AND never run for a packet no guard asks about (a plain wheel with wheelZoom// off, which is the default, walks nothing at all).@@ -3064,16 +3068,20 @@ export function Canvas() {const rect = wrap.getBoundingClientRect()const px = e.clientX - rect.leftconst py = e.clientY - rect.top- // Cap a single event's influence so a chunky mouse-wheel tick doesn't jump zoom levels.- const d = Math.max(-50, Math.min(50, e.deltaY))- const next = Math.min(2, Math.max(0.01, zoom * Math.exp(-d * 0.01)))+ // Cap a burst's influence so a chunky mouse-wheel click doesn't jump zoom levels: high-res+ // ratchet wheels (MX Master) deliver ONE detent as several packets, so the cap is a shared+ // per-burst budget rather than per-event (see wheel-zoom.ts). The speed multiplier is the+ // user's tune knob and applies only to the plain-wheel opt-in path — modifier zoom and+ // pinch keep the historical fixed step.+ const d = wheelLimiter.apply(e.deltaY, e.timeStamp)+ const next = nextWheelZoom(zoom, d, plainWheel ? wheelZoomSpeed : 1)if (next === zoom) returnconst k = next / zoomsetViewport({ x: px - (px - x) * k, y: py - (py - y) * k, zoom: next })}wrap.addEventListener('wheel', onWheel, { capture: true, passive: false })return () => wrap.removeEventListener('wheel', onWheel, { capture: true })- }, [getViewport, setViewport, wheelZoom, trackpadRouting, canvasLocked])+ }, [getViewport, setViewport, wheelZoom, wheelZoomSpeed, trackpadRouting, canvasLocked])// Double-clicking EMPTY canvas pulls back to the overview zoom — the inverse of the node// double-click, which frames one node. A fixed zoom, not "the camera the last focus came from":diff --git a/src/renderer/canvas/wheel-zoom.test.ts b/src/renderer/canvas/wheel-zoom.test.tsnew file mode 100644index 000000000..13377c1f4--- /dev/null+++ b/src/renderer/canvas/wheel-zoom.test.ts@@ -0,0 +1,87 @@+import { describe, expect, it } from 'vitest'+import {+ WheelZoomBurstLimiter,+ clampWheelZoomSpeed,+ nextWheelZoom,+ WHEEL_ZOOM_MAX_STEP+} from './wheel-zoom'++describe('WheelZoomBurstLimiter', () => {+ it('passes a small single packet through unchanged', () => {+ const limiter = new WheelZoomBurstLimiter()+ expect(limiter.apply(30, 1000)).toBe(30)+ expect(limiter.apply(-12.5, 2000)).toBe(-12.5)+ })++ it('clamps one oversized packet to the per-burst budget, preserving direction', () => {+ const limiter = new WheelZoomBurstLimiter()+ expect(limiter.apply(300, 1000)).toBe(WHEEL_ZOOM_MAX_STEP)+ expect(limiter.apply(-300, 2000)).toBe(-WHEEL_ZOOM_MAX_STEP)+ })++ it('shares one budget across a high-res detent burst (the MX Master jump)', () => {+ // An MX Master 3s detent arrives as several packets a few ms apart. Before the limiter,+ // each packet was clamped independently, so one physical click stacked two+ maxed zoom+ // steps (the observed 200% -> 84%). The whole burst must spend one budget.+ const limiter = new WheelZoomBurstLimiter()+ expect(limiter.apply(120, 1000)).toBe(WHEEL_ZOOM_MAX_STEP)+ expect(limiter.apply(120, 1004)).toBe(0)+ expect(limiter.apply(120, 1012)).toBe(0)+ })++ it('splits the budget across packets that only together exceed it', () => {+ const limiter = new WheelZoomBurstLimiter()+ expect(limiter.apply(35, 1000)).toBe(35)+ expect(limiter.apply(35, 1005)).toBe(WHEEL_ZOOM_MAX_STEP - 35)+ })++ it('refills the budget once the burst window has passed', () => {+ const limiter = new WheelZoomBurstLimiter()+ expect(limiter.apply(120, 1000)).toBe(WHEEL_ZOOM_MAX_STEP)+ expect(limiter.apply(120, 1050)).toBe(WHEEL_ZOOM_MAX_STEP)+ })++ it('leaves a smooth pinch stream untouched', () => {+ // Trackpad pinch: small deltas at ~120Hz. Must not be throttled — the limiter exists for+ // discrete wheel notches, and a pinch never spends the budget inside one window.+ const limiter = new WheelZoomBurstLimiter()+ const out: number[] = []+ for (let i = 0; i < 12; i++) out.push(limiter.apply(6, 1000 + i * 8))+ expect(out.every((d) => d === 6)).toBe(true)+ })++ it('a reversal inside an exhausted burst stays spent (no free counter-step)', () => {+ const limiter = new WheelZoomBurstLimiter()+ limiter.apply(120, 1000)+ expect(limiter.apply(-120, 1004)).toBe(0)+ })+})++describe('nextWheelZoom', () => {+ it('reproduces the historical step at speed 1', () => {+ expect(nextWheelZoom(1, 50, 1)).toBeCloseTo(Math.exp(-0.5), 10)+ })++ it('scales the exponent by the speed multiplier', () => {+ expect(nextWheelZoom(1, 50, 0.5)).toBeCloseTo(Math.exp(-0.25), 10)+ expect(nextWheelZoom(1, -25, 2)).toBeCloseTo(Math.exp(0.5), 10)+ })++ it('clamps to the canvas zoom bounds', () => {+ expect(nextWheelZoom(1.9, -50, 2)).toBe(2)+ expect(nextWheelZoom(0.011, 50, 2)).toBe(0.01)+ })+})++describe('clampWheelZoomSpeed', () => {+ it('passes sane values through and defaults the rest to 1', () => {+ expect(clampWheelZoomSpeed(0.5)).toBe(0.5)+ expect(clampWheelZoomSpeed(undefined)).toBe(1)+ expect(clampWheelZoomSpeed(Number.NaN)).toBe(1)+ })++ it('clamps hand-edited settings.json values into range', () => {+ expect(clampWheelZoomSpeed(0)).toBe(0.2)+ expect(clampWheelZoomSpeed(99)).toBe(2)+ })+})diff --git a/src/renderer/canvas/wheel-zoom.ts b/src/renderer/canvas/wheel-zoom.tsnew file mode 100644index 000000000..1b8e4605f--- /dev/null+++ b/src/renderer/canvas/wheel-zoom.ts@@ -0,0 +1,62 @@+/**+ * Wheel-zoom step shaping for the canvas — the pure half of Canvas.tsx's capture-phase wheel+ * handler.+ *+ * The per-EVENT clamp that used to live inline there assumed a classic notched wheel: one+ * physical click, one wheel event, so capping the event capped the click. High-resolution+ * ratchet wheels (Logitech MX Master 3S and friends) break that assumption — Chromium delivers+ * one detent as several pixel-mode packets a few milliseconds apart, each of which passed the+ * old clamp independently. Two maxed packets compound to exp(1) ≈ 2.7×, which is the reported+ * "one click jumped 200% → 84%".+ *+ * `WheelZoomBurstLimiter` therefore budgets by TIME, not by packet: every packet inside one+ * short burst window spends from a single ±`WHEEL_ZOOM_MAX_STEP` budget, so a detent zooms the+ * same amount whether the OS delivers it as one packet or four. The window is deliberately+ * shorter than any human's click cadence (a fast scroller manages ~8 clicks/sec ≈ 125 ms apart)+ * and long enough to cover a detent's packet spread; successive deliberate clicks each get a+ * fresh budget. A trackpad pinch (ctrl+wheel) flows through the same limiter but never feels+ * it: its packets are small and the per-window budget allows exp(0.5) per 40 ms ≈ 25× per+ * second, far beyond any physical pinch.+ */++/** One burst's total influence on zoom, in deltaY pixels — the historical per-event cap. */+export const WHEEL_ZOOM_MAX_STEP = 50++/** Packets closer together than this share one budget; must stay well under ~125 ms so+ * 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.01++export class WheelZoomBurstLimiter {+ private burstStart = Number.NEGATIVE_INFINITY+ private spent = 0++ /** Returns how much of `deltaY` may influence zoom right now; 0 when the burst is spent. */+ apply(deltaY: number, now: number): number {+ if (now - this.burstStart >= BURST_WINDOW_MS) {+ this.burstStart = now+ this.spent = 0+ }+ // The budget is on absolute influence: a reversal inside an exhausted burst is device+ // jitter, not intent, and must not get a free counter-step.+ const remaining = WHEEL_ZOOM_MAX_STEP - this.spent+ const step = Math.sign(deltaY) * Math.min(Math.abs(deltaY), remaining)+ this.spent += Math.abs(step)+ return step || 0 // canonicalize -0 (sign(-x) * exhausted budget)+ }+}++/** 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)))++/** 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's+ * range. */+export const clampWheelZoomSpeed = (speed: number | undefined): number =>+ typeof speed === 'number' && Number.isFinite(speed) ? Math.min(2, Math.max(0.2, speed)) : 1diff --git a/src/renderer/components/settings/sections/BehaviorSection.tsx b/src/renderer/components/settings/sections/BehaviorSection.tsxindex 026be981d..21448bfd1 100644--- a/src/renderer/components/settings/sections/BehaviorSection.tsx+++ b/src/renderer/components/settings/sections/BehaviorSection.tsx@@ -8,6 +8,7 @@ import { Select } from '@renderer/ui/Select'import { SegmentedPill } from '@renderer/ui/SegmentedPill'import { Input } from '@renderer/ui/Input'import { hintLabel } from '@shared/platform-utils'+import { clampWheelZoomSpeed } from '@renderer/canvas/wheel-zoom'import { DEFAULT_WORKTREE_PATH_TEMPLATE } from '@shared/worktree'const ROWS = {@@ -40,6 +41,10 @@ const ROWS = {keywords: ['worktree', 'git', 'path', 'folder', 'repo', 'branch', 'template']},wheelZoom: { title: 'Scroll wheel zooms', keywords: ['zoom', 'wheel', 'scroll', 'mouse', 'pan'] },+ wheelZoomSpeed: {+ title: 'Wheel zoom speed',+ keywords: ['zoom', 'wheel', 'speed', 'sensitivity', 'step', 'jump', 'mouse', 'scroll']+ },trackpadPan: {title: 'Trackpad scroll pans',keywords: ['trackpad', 'pan', 'scroll', 'zoom', 'magic', 'mouse', 'two-finger', 'macos']@@ -233,6 +238,37 @@ export function BehaviorSection({ isActive }: { isActive: boolean }): React.JSX.}/></SearchableRow>+ <div+ className={+ 'mt-3 space-y-3 border-l border-border pl-4' ++ (settings.wheelZoom ? '' : ' pointer-events-none opacity-40')+ }+ aria-disabled={!settings.wheelZoom}+ >+ <SearchableRow {...ROWS.wheelZoomSpeed}>+ <FieldRow+ label="Wheel zoom speed"+ description="How far one wheel click zooms. Turn it down if a single click jumps too far (common on high-resolution wheels like the MX Master)."+ control={+ <div className="flex items-center gap-3">+ <input+ type="range"+ min={0.2}+ max={2}+ step={0.1}+ value={clampWheelZoomSpeed(settings.wheelZoomSpeed)}+ aria-label="Wheel zoom speed"+ onChange={(e) => update({ wheelZoomSpeed: Number(e.target.value) })}+ className="w-40 accent-[var(--accent)]"+ />+ <span className="w-12 text-right text-[12px] text-muted tabular-nums">+ {clampWheelZoomSpeed(settings.wheelZoomSpeed).toFixed(1)}×+ </span>+ </div>+ }+ />+ </SearchableRow>+ </div><SearchableRow {...ROWS.trackpadPan}><FieldRowlabel="Trackpad scroll pans"diff --git a/src/shared/types.ts b/src/shared/types.tsindex c3f6dac5b..bde723a06 100644--- a/src/shared/types.ts+++ b/src/shared/types.ts@@ -1218,6 +1218,11 @@ export interface Settings {* scroll keeps panning independently (see canvas/wheel-gesture.ts), so mouse and trackpad* coexist; elsewhere this still trades away scroll-to-pan, so it stays opt-in. */wheelZoom: boolean+ /** How far one plain wheel click zooms, as a multiplier on the canvas zoom step (0.2–2,+ * default 1 = historical feel). Applies only to the `wheelZoom` path — Cmd/Ctrl+wheel and+ * pinch keep the fixed step, so tuning a chunky mouse down never slows the trackpad.+ * Validated at point of use (canvas/wheel-zoom.ts `clampWheelZoomSpeed`). */+ wheelZoomSpeed: number/** macOS only: a two-finger trackpad scroll pans the canvas, independently of `wheelZoom`* (see canvas/wheel-gesture.ts). Off restores the pre-router behavior — `wheelZoom` alone* decides — which is also the recourse for a precise-pixel MOUSE that reads as a trackpad. */@@ -1479,6 +1484,7 @@ export const DEFAULT_SETTINGS: Settings = {doubleClickFocus: true,terminalMiddleClickPaste: false,wheelZoom: false,+ wheelZoomSpeed: 1,trackpadPan: true,canvasDragMode: 'select',browserMemorySaver: true,