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.

feat(canvas): ⌘+middle-drag pans past the lock; lock toggle command; close the middle-drag leak (#1167)

Paul Robertson8d3a2edc2540
diff --git a/CLAUDE.md b/CLAUDE.md
index 6a793905d..d85310cf0 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -483,6 +483,18 @@ project's nodes only.** The contract:
machine-local, but in the **Server Edition** the setting rides that server's settings.json
(shared by every browser hitting it) while the bit is per browser PROFILE, so two profiles can
legitimately disagree about the lock. Desktop + Server Edition; **Mobile: N/A** (no canvas).
+ **The lock covers middle-drag on NODES too, and ⌘/Ctrl+middle-drag gets past it** (issue
+ #1130, `renderer/lib/modifierPan.ts`). React Flow's zoom filter accepts a middle-button
+ `mousedown` on a node / edge / selection before it reads `panOnDrag`, so turning `panOnDrag` off
+ never stopped a middle-drag that started on a node header or a terminal's hover guard (the xterm
+ itself was only safe by accident, via the #84 middle-click guard). While locked,
+ `installLockedMiddleGuard` stops a middle `mousedown` in the BUBBLE phase on
+ `.react-flow__viewport` — after the node (tmux, the middle-click paste setting) has seen it, before
+ React Flow's listener on an ancestor. `installModifierPan` is the deliberate way past the lock:
+ ⌘+middle-drag (Ctrl off-mac) pans anywhere, locked or not, by cancelling the pointerdown in the
+ capture phase on the flow wrapper (so no `mousedown` reaches d3, d3-drag or xterm). The
+ `canvas.toggleLock` command ships UNBOUND (⌘⇧L is the sessions sidebar's) and, like every canvas
+ command, does not fire while a terminal has the keyboard.
It is one GLOBAL bit rather than per-project
because `<Canvas />` is mounted once and is not keyed by project, so the lock always carried
across project switches within a session. Restore is gated on settings HYDRATION (Canvas mounts
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 233036561..34d5f3937 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -249,6 +249,7 @@ import { handoffsFor, installHandoffFocusReset, noteHandoff, suppressDoneAfterHa
import { loadIdentity } from '../state/presence'
import { runBoardKey } from '../lib/boardKeys'
import { readCanvasLocked, writeCanvasLocked } from '../lib/canvasLock'
+import { installLockedMiddleGuard, installModifierPan } from '../lib/modifierPan'
import {
FLOW_NODE_CLASS,
isFocusTarget,
@@ -5128,6 +5129,25 @@ export function Canvas() {
}
}, [getViewport, setViewport, wheelZoom, wheelZoomSpeed, trackpadRouting, canvasLocked])
+ // ⌘+middle-drag (Ctrl off-mac) pans the camera even while the canvas lock is on, and over any
+ // node — the explicit "move the map" gesture (issue #1130; lib/modifierPan). Not gated on
+ // `canvasLocked` on purpose: getting past the lock is the point.
+ useEffect(() => {
+ const wrap = flowWrapRef.current
+ if (wrap === null) return
+ return installModifierPan(wrap, { isMac, getViewport, setViewport: (v) => void setViewport(v) })
+ }, [getViewport, setViewport])
+
+ // …and the lock really freezes a PLAIN middle-drag: React Flow lets a middle press on a node,
+ // edge or selection pan even with `panOnDrag` off, so a drag started on a node header (or a
+ // terminal's hover guard) slid the map past the lock (lib/modifierPan installLockedMiddleGuard).
+ useEffect(() => {
+ if (!canvasLocked) return
+ const viewport = flowWrapRef.current?.querySelector<HTMLElement>('.react-flow__viewport')
+ if (viewport === null || viewport === undefined) return
+ return installLockedMiddleGuard(viewport)
+ }, [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":
// a remembered viewport depends on invisible state (which focus? still armed?), so the same
@@ -10075,6 +10095,7 @@ export function Canvas() {
'canvas.fitAll': () => { fitAll(); return true },
'canvas.tidy': () => { arrangeAllNodes(); return true },
'canvas.tidyLineage': () => { arrangeByLineageAction(); return true },
+ 'canvas.toggleLock': () => { setCanvasLocked((v) => !v); return true },
// The kanban board's keys — the mounted board decides (and declines when the focused control
// owns the key, or when no per-project board is up: Omni registers none). lib/boardKeys.
'board.openCard': () => runBoardKey('open'),
@@ -18903,7 +18924,11 @@ export function Canvas() {
</ControlButton>
</Tooltip>
<Tooltip
- label={canvasLocked ? 'Unlock view (pan/zoom)' : 'Lock view (pan/zoom); nodes stay movable'}
+ label={
+ canvasLocked
+ ? `Unlock view (pan/zoom). ${isMac ? '⌘' : 'Ctrl'}+middle-drag still pans`
+ : 'Lock view (pan/zoom); nodes stay movable'
+ }
placement="right"
>
<ControlButton
diff --git a/src/renderer/components/ShortcutsPanel.tsx b/src/renderer/components/ShortcutsPanel.tsx
index 64e0b5090..2defd1c41 100644
--- a/src/renderer/components/ShortcutsPanel.tsx
+++ b/src/renderer/components/ShortcutsPanel.tsx
@@ -134,6 +134,8 @@ function extraRows(group: CommandGroup, o: ShortcutSectionsOptions): ShortcutRow
row(['Middle-drag'], 'Pan the canvas')
]),
row(['Space', 'drag'], 'Pan the canvas (any drag mode)'),
+ // lib/modifierPan: deliberately ⌘ on mac and Ctrl elsewhere, so spelled per platform.
+ row([o.isMac ? '⌘' : 'Ctrl', 'middle-drag'], 'Pan the canvas, even while it is locked'),
row(['⇧', 'click'], 'Add a node to the selection'),
...(o.doubleClickFocus
? [row(['Double-click'], 'Center & focus a node')]
diff --git a/src/renderer/lib/modifierPan.test.ts b/src/renderer/lib/modifierPan.test.ts
new file mode 100644
index 000000000..ea10311b9
--- /dev/null
+++ b/src/renderer/lib/modifierPan.test.ts
@@ -0,0 +1,168 @@
+// @vitest-environment jsdom
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { installLockedMiddleGuard, installModifierPan, isModifierPanStart, type PanViewport } from './modifierPan'
+
+const mods = { metaKey: false, ctrlKey: false, altKey: false, shiftKey: false }
+
+describe('isModifierPanStart', () => {
+ it('is the middle button with ⌘ on macOS', () => {
+ expect(isModifierPanStart({ ...mods, button: 1, metaKey: true }, true)).toBe(true)
+ expect(isModifierPanStart({ ...mods, button: 1, ctrlKey: true }, true)).toBe(false)
+ })
+
+ it('is the middle button with Ctrl elsewhere', () => {
+ expect(isModifierPanStart({ ...mods, button: 1, ctrlKey: true }, false)).toBe(true)
+ expect(isModifierPanStart({ ...mods, button: 1, metaKey: true }, false)).toBe(false)
+ })
+
+ it('is not a plain middle-drag, another button, or a chord with extra modifiers', () => {
+ expect(isModifierPanStart({ ...mods, button: 1 }, true)).toBe(false)
+ expect(isModifierPanStart({ ...mods, button: 0, metaKey: true }, true)).toBe(false)
+ expect(isModifierPanStart({ ...mods, button: 1, metaKey: true, shiftKey: true }, true)).toBe(false)
+ expect(isModifierPanStart({ ...mods, button: 1, metaKey: true, altKey: true }, true)).toBe(false)
+ expect(isModifierPanStart({ ...mods, button: 1, metaKey: true, ctrlKey: true }, true)).toBe(false)
+ })
+})
+
+/** jsdom has no PointerEvent constructor in every version; a MouseEvent carrying a pointerId is
+ * what the handler reads. */
+function pointer(type: string, init: MouseEventInit & { pointerId?: number }): MouseEvent {
+ const e = new MouseEvent(type, { bubbles: true, cancelable: true, ...init })
+ Object.defineProperty(e, 'pointerId', { value: init.pointerId ?? 1 })
+ return e
+}
+
+describe('installModifierPan', () => {
+ let wrap: HTMLDivElement
+ let child: HTMLDivElement
+ let viewport: PanViewport
+ let uninstall: () => void
+ const setViewport = vi.fn((v: PanViewport) => {
+ viewport = v
+ })
+
+ beforeEach(() => {
+ wrap = document.createElement('div')
+ child = document.createElement('div') // stands in for a node / terminal under the pointer
+ wrap.appendChild(child)
+ document.body.appendChild(wrap)
+ viewport = { x: 10, y: 20, zoom: 0.5 }
+ setViewport.mockClear()
+ uninstall = installModifierPan(wrap, { isMac: true, getViewport: () => viewport, setViewport })
+ })
+
+ afterEach(() => {
+ uninstall()
+ document.body.innerHTML = ''
+ })
+
+ it('pans the camera by the pointer movement, keeping the zoom', () => {
+ child.dispatchEvent(pointer('pointerdown', { button: 1, metaKey: true, clientX: 100, clientY: 100 }))
+
+ child.dispatchEvent(pointer('pointermove', { clientX: 130, clientY: 90 }))
+ child.dispatchEvent(pointer('pointermove', { clientX: 140, clientY: 95 }))
+
+ expect(viewport).toEqual({ x: 50, y: 15, zoom: 0.5 })
+ })
+
+ it('keeps the gesture from the node underneath (cancelled and stopped in the capture phase)', () => {
+ const below = vi.fn()
+ child.addEventListener('pointerdown', below)
+ const down = pointer('pointerdown', { button: 1, metaKey: true })
+
+ child.dispatchEvent(down)
+
+ expect(below).not.toHaveBeenCalled()
+ expect(down.defaultPrevented).toBe(true)
+ })
+
+ it('stops panning at pointerup and swallows the auxclick that follows', () => {
+ child.dispatchEvent(pointer('pointerdown', { button: 1, metaKey: true, clientX: 0, clientY: 0 }))
+ child.dispatchEvent(pointer('pointerup', { button: 1, clientX: 0, clientY: 0 }))
+ const aux = new MouseEvent('auxclick', { bubbles: true, cancelable: true, button: 1 })
+ child.dispatchEvent(aux)
+
+ child.dispatchEvent(pointer('pointermove', { clientX: 50, clientY: 50 }))
+
+ expect(aux.defaultPrevented).toBe(true)
+ expect(setViewport).not.toHaveBeenCalled()
+ })
+
+ it('leaves a plain middle-drag to React Flow (and the lock)', () => {
+ const down = pointer('pointerdown', { button: 1, clientX: 0, clientY: 0 })
+ child.dispatchEvent(down)
+ child.dispatchEvent(pointer('pointermove', { clientX: 50, clientY: 50 }))
+ const aux = new MouseEvent('auxclick', { bubbles: true, cancelable: true, button: 1 })
+ child.dispatchEvent(aux)
+
+ expect(down.defaultPrevented).toBe(false)
+ expect(aux.defaultPrevented).toBe(false)
+ expect(setViewport).not.toHaveBeenCalled()
+ })
+
+ it('stops listening once uninstalled', () => {
+ uninstall()
+
+ child.dispatchEvent(pointer('pointerdown', { button: 1, metaKey: true, clientX: 0, clientY: 0 }))
+ child.dispatchEvent(pointer('pointermove', { clientX: 50, clientY: 50 }))
+
+ expect(setViewport).not.toHaveBeenCalled()
+ uninstall = () => {}
+ })
+})
+
+describe('installLockedMiddleGuard', () => {
+ /** zoomPane > viewport > node > header: React Flow's pan listens on the zoom pane. */
+ function tree() {
+ const zoomPane = document.createElement('div')
+ const viewport = document.createElement('div')
+ const node = document.createElement('div')
+ zoomPane.appendChild(viewport)
+ viewport.appendChild(node)
+ document.body.appendChild(zoomPane)
+ return { zoomPane, viewport, node }
+ }
+ const press = (button: number) => new MouseEvent('mousedown', { bubbles: true, cancelable: true, button })
+
+ afterEach(() => {
+ document.body.innerHTML = ''
+ })
+
+ it('keeps a middle press on a node from reaching React Flow, after the node has seen it', () => {
+ const { zoomPane, viewport, node } = tree()
+ const reactFlow = vi.fn()
+ const nodeSaw = vi.fn()
+ zoomPane.addEventListener('mousedown', reactFlow)
+ node.addEventListener('mousedown', nodeSaw)
+ installLockedMiddleGuard(viewport)
+
+ node.dispatchEvent(press(1))
+
+ expect(nodeSaw).toHaveBeenCalledTimes(1)
+ expect(reactFlow).not.toHaveBeenCalled()
+ })
+
+ it('leaves the left and right buttons alone (node drag, context menu)', () => {
+ const { zoomPane, viewport, node } = tree()
+ const reactFlow = vi.fn()
+ zoomPane.addEventListener('mousedown', reactFlow)
+ installLockedMiddleGuard(viewport)
+
+ node.dispatchEvent(press(0))
+ node.dispatchEvent(press(2))
+
+ expect(reactFlow).toHaveBeenCalledTimes(2)
+ })
+
+ it('stops guarding once uninstalled (the canvas was unlocked)', () => {
+ const { zoomPane, viewport, node } = tree()
+ const reactFlow = vi.fn()
+ zoomPane.addEventListener('mousedown', reactFlow)
+ const uninstall = installLockedMiddleGuard(viewport)
+
+ uninstall()
+ node.dispatchEvent(press(1))
+
+ expect(reactFlow).toHaveBeenCalledTimes(1)
+ })
+})
diff --git a/src/renderer/lib/modifierPan.ts b/src/renderer/lib/modifierPan.ts
new file mode 100644
index 000000000..668cdb2a5
--- /dev/null
+++ b/src/renderer/lib/modifierPan.ts
@@ -0,0 +1,125 @@
+/**
+ * ⌘+middle-drag (Ctrl+middle-drag off-mac) pans the canvas — ALWAYS: whether or not the canvas
+ * lock is on, and wherever the pointer is, a terminal included (issue #1130).
+ *
+ * The lock exists so the canvas stops sliding when a scroll or drag meant for a terminal lands on
+ * it instead; it is often left on for a whole session. Unlocking to move the camera and locking
+ * again is three clicks for one intended pan. A middle-drag with the primary modifier held is never
+ * an accident and has no other meaning on the canvas, so it pans past the lock. Plain middle-drag
+ * is unchanged: it pans when unlocked and does nothing when locked.
+ *
+ * React Flow's `panOnDrag` chooses mouse BUTTONS only (no modifier), and it is off entirely while
+ * locked, so this is the canvas's own pointer handler — the same shape as the wheel-zoom handler.
+ * It listens in the CAPTURE phase on the flow wrapper and cancels the pointerdown, which (by the
+ * Pointer Events spec) suppresses the compatibility mouse events: d3-zoom, d3-drag and xterm all
+ * listen to `mousedown`, so none of them sees the gesture — no node drag, no tmux mouse event.
+ * The `auxclick` that follows is cancelled too, so Linux's middle-click paste and a browser's
+ * middle-click handling stay out of it.
+ */
+
+export interface PanViewport {
+ x: number
+ y: number
+ zoom: number
+}
+
+/** Whether this pointerdown starts a modifier pan: the middle button with exactly the primary
+ * modifier (⌘ on macOS, Ctrl elsewhere). Shift / Alt / the other modifier keep their meanings. */
+export function isModifierPanStart(
+ e: Pick<PointerEvent, 'button' | 'metaKey' | 'ctrlKey' | 'altKey' | 'shiftKey'>,
+ isMac: boolean
+): boolean {
+ if (e.button !== 1 || e.altKey || e.shiftKey) return false
+ return isMac ? e.metaKey && !e.ctrlKey : e.ctrlKey && !e.metaKey
+}
+
+export interface ModifierPanDeps {
+ isMac: boolean
+ getViewport: () => PanViewport
+ setViewport: (v: PanViewport) => void
+}
+
+/** Install the gesture on the flow wrapper. Returns the uninstaller. */
+export function installModifierPan(wrap: HTMLElement, deps: ModifierPanDeps): () => void {
+ let active: { pointerId: number; lastX: number; lastY: number } | null = null
+ // The auxclick that ends a modifier pan arrives after pointerup; it is swallowed once.
+ let swallowAuxclick = false
+
+ const end = (e: PointerEvent): void => {
+ if (active === null || e.pointerId !== active.pointerId) return
+ active = null
+ swallowAuxclick = true
+ wrap.releasePointerCapture?.(e.pointerId)
+ e.preventDefault()
+ e.stopPropagation()
+ }
+
+ const onDown = (e: PointerEvent): void => {
+ // A pan released outside the window may never get its auxclick; never carry that over.
+ swallowAuxclick = false
+ if (!isModifierPanStart(e, deps.isMac)) return
+ e.preventDefault()
+ e.stopPropagation()
+ active = { pointerId: e.pointerId, lastX: e.clientX, lastY: e.clientY }
+ // Keep receiving moves when the pointer leaves the wrapper (or the window) mid-drag.
+ wrap.setPointerCapture?.(e.pointerId)
+ }
+
+ const onMove = (e: PointerEvent): void => {
+ if (active === null || e.pointerId !== active.pointerId) return
+ e.preventDefault()
+ e.stopPropagation()
+ const dx = e.clientX - active.lastX
+ const dy = e.clientY - active.lastY
+ active.lastX = e.clientX
+ active.lastY = e.clientY
+ if (dx === 0 && dy === 0) return
+ const v = deps.getViewport()
+ deps.setViewport({ x: v.x + dx, y: v.y + dy, zoom: v.zoom })
+ }
+
+ const onAuxclick = (e: MouseEvent): void => {
+ if (!swallowAuxclick || e.button !== 1) return
+ swallowAuxclick = false
+ e.preventDefault()
+ e.stopPropagation()
+ }
+
+ wrap.addEventListener('pointerdown', onDown, { capture: true })
+ wrap.addEventListener('pointermove', onMove, { capture: true })
+ wrap.addEventListener('pointerup', end, { capture: true })
+ wrap.addEventListener('pointercancel', end, { capture: true })
+ wrap.addEventListener('auxclick', onAuxclick, { capture: true })
+ return () => {
+ wrap.removeEventListener('pointerdown', onDown, { capture: true })
+ wrap.removeEventListener('pointermove', onMove, { capture: true })
+ wrap.removeEventListener('pointerup', end, { capture: true })
+ wrap.removeEventListener('pointercancel', end, { capture: true })
+ wrap.removeEventListener('auxclick', onAuxclick, { capture: true })
+ }
+}
+
+/**
+ * While the canvas is locked, keep a plain middle press inside the viewport (on a node, an edge or
+ * a selection box) from reaching React Flow's pan.
+ *
+ * The lock works by turning React Flow's `panOnDrag` off, but React Flow's zoom filter
+ * (`@xyflow/system` `createFilter`) accepts a middle-button `mousedown` on a node / edge /
+ * selection BEFORE it looks at `panOnDrag`, so a middle-drag that started on one panned straight
+ * past the lock (#1130). Whether it did depended on what was under the pointer: a node header and
+ * a terminal's hover guard leaked, the xterm itself did not (the #84 middle-click guard stops the
+ * press there — unless middle-click paste is on), and empty canvas never did (the pane is outside
+ * the viewport and React Flow honours `panOnDrag` there).
+ *
+ * The listener is on the VIEWPORT in the BUBBLE phase: everything inside it — the terminal, tmux's
+ * middle click, the middle-click paste setting — has already seen the press; only React Flow's
+ * listener, on an ancestor, is cut off. ⌘/Ctrl+middle never gets here (installModifierPan cancels
+ * that pointerdown, so no `mousedown` follows). Install only while locked; returns the uninstaller.
+ */
+export function installLockedMiddleGuard(viewport: HTMLElement): () => void {
+ const onMouseDown = (e: MouseEvent): void => {
+ if (e.button === 1) e.stopPropagation()
+ }
+ viewport.addEventListener('mousedown', onMouseDown)
+ return () => viewport.removeEventListener('mousedown', onMouseDown)
+}
diff --git a/src/shared/keybindings.test.ts b/src/shared/keybindings.test.ts
index 35ad97f8a..b78d9994b 100644
--- a/src/shared/keybindings.test.ts
+++ b/src/shared/keybindings.test.ts
@@ -110,6 +110,8 @@ describe('registry invariants', () => {
darwin: [], other: [] },
{ id: 'canvas.groupSelection', title: 'Group selection', group: 'Canvas', scope: 'canvas',
darwin: [], other: [] },
+ { id: 'canvas.toggleLock', title: 'Toggle canvas lock', group: 'Canvas', scope: 'canvas',
+ darwin: [], other: [] },
{ id: 'node.newTerminal', title: 'New terminal node', group: 'Nodes', scope: 'canvas',
darwin: ['Cmd+T'], other: ['Cmd+T'] },
{ id: 'node.newAgent', title: 'New agent node', group: 'Nodes', scope: 'canvas',
diff --git a/src/shared/keybindings.ts b/src/shared/keybindings.ts
index eca8638f4..77289afb1 100644
--- a/src/shared/keybindings.ts
+++ b/src/shared/keybindings.ts
@@ -66,6 +66,7 @@ export type CommandId =
| 'canvas.fitAll'
| 'canvas.tidy'
| 'canvas.tidyLineage'
+ | 'canvas.toggleLock'
| 'canvas.groupSelection'
| 'node.newTerminal'
| 'node.newAgent'
@@ -169,6 +170,10 @@ export const COMMAND_DEFINITIONS: readonly CommandDefinition[] = [
defaultBindings: both() },
{ id: 'canvas.groupSelection', title: 'Group selection', group: 'Canvas', scope: 'canvas',
defaultBindings: both() },
+ { id: 'canvas.toggleLock', title: 'Toggle canvas lock', group: 'Canvas', scope: 'canvas',
+ // Ships unbound (issue #1130): the obvious chord, Cmd+Shift+L, is the sessions sidebar's.
+ // Not allowInTerminal — a focused terminal keeps the chord, like every canvas command.
+ defaultBindings: both() },
// Nodes
{ id: 'node.newTerminal', title: 'New terminal node', group: 'Nodes', scope: 'canvas',