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): hold SPACE to pan, like Figma (#86)

enes7e6a3d44b701
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 1608c30b0..46a0f6fbb 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -110,6 +110,7 @@ import { markMobileLaunchSeen, shouldShowMobileLaunch } from '../lib/mobileLaunc
import type { DictationTarget } from '../components/DictationOverlay'
import { describeOs, REPO_URL } from '../lib/bugReport'
import { shouldReleasePaneFocus } from '../lib/paneFocus'
+import { isSpaceRelease, spacePanKeydown } from '../lib/spacePan'
import { UpdateCard } from '../components/UpdateCard'
import { AnnouncementBanner } from '../components/AnnouncementBanner'
import { TmuxBanner } from '../components/TmuxBanner'
@@ -642,6 +643,47 @@ export function Canvas() {
// Flow's own lock convention. Transient by design: a lock that survives restart reads as
// "the app is frozen" to whoever opens it next.
const [canvasLocked, setCanvasLocked] = useState(false)
+ /** SPACE is held: a left-drag pans instead of box-selecting, Figma-style (issue #86). */
+ const [spacePan, setSpacePan] = useState(false)
+
+ /**
+ * Hold SPACE to pan — the Figma/Miro gesture, requested in issue #86 (where a user pressed it,
+ * got nothing, and watched the spaces land in a sticky note instead).
+ *
+ * CAPTURE phase, because the answer has to be decided before anything else sees the key. What is
+ * NOT taken is the load-bearing half — `spacePanKeydown` refuses a modified space, the auto-repeat
+ * of a held key, and above all anything typed into a terminal, a note or a field. A space
+ * swallowed there is a wrong character in the user's text, which is a worse bug than the missing
+ * gesture this adds. (xterm needs no special case: it takes the keyboard through a hidden
+ * textarea, so a focused terminal reads as a typing target like any other.)
+ *
+ * `preventDefault` only while we actually engage: an untaken space must reach whoever it was for.
+ *
+ * The three RELEASE paths all matter, and only the first is obvious. A keyup ends the ordinary
+ * gesture; a window blur ends the one where the user switched apps mid-pan (⌘Tab with space held
+ * would otherwise never deliver a keyup, stranding the canvas in grab mode until the next tap);
+ * and the lock is honoured by the props rather than here, so locking mid-pan cannot leave a
+ * half-engaged state either.
+ */
+ useEffect(() => {
+ const onKeyDown = (e: KeyboardEvent): void => {
+ if (spacePanKeydown(e, document.activeElement) !== 'engage') return
+ e.preventDefault()
+ setSpacePan(true)
+ }
+ const onKeyUp = (e: KeyboardEvent): void => {
+ if (isSpaceRelease(e)) setSpacePan(false)
+ }
+ const release = (): void => setSpacePan(false)
+ window.addEventListener('keydown', onKeyDown, true)
+ window.addEventListener('keyup', onKeyUp, true)
+ window.addEventListener('blur', release)
+ return () => {
+ window.removeEventListener('keydown', onKeyDown, true)
+ window.removeEventListener('keyup', onKeyUp, true)
+ window.removeEventListener('blur', release)
+ }
+ }, [])
const [menu, setMenu] = useState<{ x: number; y: number; items: MenuItem[] } | null>(null)
const [remotePicker, setRemotePicker] = useState<{ x: number; y: number } | null>(null)
const [paletteOpen, setPaletteOpen] = useState(false)
@@ -7573,11 +7615,17 @@ export function Canvas() {
// shows the grab cursor whenever panOnDrag includes button 0); box-select stays
// reachable via Shift+drag (selectionKeyCode's default). 'select' keeps the
// Figma-style default: left-drag rubber-band selects, pan is middle-drag/scroll.
- selectionOnDrag={settings.canvasDragMode !== 'pan'}
+ selectionOnDrag={!spacePan && settings.canvasDragMode !== 'pan'}
selectionMode={SelectionMode.Partial}
// The lock freezes the CAMERA only (pan/zoom) — nodes stay draggable, resizable and
// connectable: the point is "stop the map sliding under me", not "freeze my work".
- panOnDrag={canvasLocked ? false : settings.canvasDragMode === 'pan' ? [0, 1] : [1]}
+ panOnDrag={
+ canvasLocked
+ ? false
+ : spacePan || settings.canvasDragMode === 'pan'
+ ? [0, 1]
+ : [1]
+ }
panOnScroll={canvasLocked ? false : !wheelZoom}
zoomOnScroll={false}
zoomOnPinch={false}
diff --git a/src/renderer/lib/spacePan.test.ts b/src/renderer/lib/spacePan.test.ts
new file mode 100644
index 000000000..b681a39c9
--- /dev/null
+++ b/src/renderer/lib/spacePan.test.ts
@@ -0,0 +1,64 @@
+import { describe, expect, it } from 'vitest'
+import { isSpaceRelease, spacePanKeydown, typingTarget } from './spacePan'
+
+const el = (tagName: string, contentEditable = false): Element =>
+ ({ tagName, isContentEditable: contentEditable }) as unknown as Element
+
+/**
+ * Issue #86 asked for the Figma gesture: hold space, left-drag, pan. The tests that matter are the
+ * REFUSALS — space is not a spare key on this canvas, it is a character in every terminal and every
+ * note, and a space swallowed there is a wrong character in the user's text rather than a missing
+ * pan. That is a worse bug than the one being fixed, so it is the one pinned hardest.
+ */
+describe('spacePanKeydown', () => {
+ it('engages on a plain space over the canvas', () => {
+ expect(spacePanKeydown({ key: ' ' }, null)).toBe('engage')
+ expect(spacePanKeydown({ key: ' ' }, el('DIV'))).toBe('engage')
+ expect(spacePanKeydown({ key: ' ' }, el('BUTTON'))).toBe('engage')
+ })
+
+ it('NEVER takes a space that is being typed', () => {
+ for (const target of [el('TEXTAREA'), el('INPUT'), el('DIV', true)]) {
+ expect(spacePanKeydown({ key: ' ' }, target)).toBe('ignore')
+ }
+ })
+
+ it('leaves a focused TERMINAL alone — xterm types through a hidden textarea', () => {
+ // No special case for xterm anywhere in this feature; this is why none is needed.
+ expect(typingTarget(el('TEXTAREA'))).toBe(true)
+ })
+
+ it('ignores a MODIFIED space, which belongs to someone else', () => {
+ // ⌘Space is the OS switcher; Ctrl/Alt+Space are other people's bindings.
+ expect(spacePanKeydown({ key: ' ', metaKey: true }, null)).toBe('ignore')
+ expect(spacePanKeydown({ key: ' ', ctrlKey: true }, null)).toBe('ignore')
+ expect(spacePanKeydown({ key: ' ', altKey: true }, null)).toBe('ignore')
+ })
+
+ it('ignores the auto-repeat, so a held key engages once rather than sixty times a second', () => {
+ expect(spacePanKeydown({ key: ' ', repeat: true }, null)).toBe('ignore')
+ })
+
+ it('ignores every other key', () => {
+ for (const key of ['a', 'Enter', 'Shift', 'ArrowLeft']) {
+ expect(spacePanKeydown({ key }, null)).toBe('ignore')
+ }
+ })
+})
+
+describe('isSpaceRelease', () => {
+ it('ends the gesture on the space keyup', () => {
+ expect(isSpaceRelease({ key: ' ' })).toBe(true)
+ expect(isSpaceRelease({ key: 'Spacebar' })).toBe(true)
+ })
+
+ it('is modifier-BLIND, so a pan can always be released', () => {
+ // Tapping ⌘ mid-pan still delivers a keyup for space. Requiring an unmodified release would
+ // strand the canvas in grab mode until the user pressed space again.
+ expect(isSpaceRelease({ key: ' ', metaKey: true })).toBe(true)
+ })
+
+ it('ignores other keys coming up', () => {
+ expect(isSpaceRelease({ key: 'a' })).toBe(false)
+ })
+})
diff --git a/src/renderer/lib/spacePan.ts b/src/renderer/lib/spacePan.ts
new file mode 100644
index 000000000..892a72cdb
--- /dev/null
+++ b/src/renderer/lib/spacePan.ts
@@ -0,0 +1,64 @@
+/**
+ * Space-to-pan — the Figma/Miro reflex, asked for in issue #86.
+ *
+ * Holding SPACE turns a left-drag on the canvas into a pan for as long as it is held. The pure
+ * decisions live here because the failure modes are all about WHEN it may engage, and every one of
+ * them is testable without a DOM.
+ */
+
+/** What a space keydown should do. */
+export type SpacePanAction = 'engage' | 'ignore'
+
+/**
+ * Is this element one that a space keystroke BELONGS to?
+ *
+ * The whole feature turns on this question, because space is not a spare key: it is a character in
+ * every terminal and every note on the canvas. Getting it wrong does not degrade panning, it
+ * corrupts what the user is typing.
+ *
+ * xterm is covered without a special case, and that is not luck: xterm takes the keyboard through a
+ * hidden `<textarea>`, so a focused terminal answers true here exactly like a sticky note does.
+ */
+export function typingTarget(active: Element | null): boolean {
+ if (!active) return false
+ const tag = active.tagName
+ if (tag === 'TEXTAREA' || tag === 'INPUT') return true
+ return (active as HTMLElement).isContentEditable === true
+}
+
+/** The event shape this reads — a `KeyboardEvent` satisfies it, and so does a test literal. */
+export interface SpaceKeyEvent {
+ key: string
+ /** True for the auto-repeat that follows a held key. */
+ repeat?: boolean
+ ctrlKey?: boolean
+ metaKey?: boolean
+ altKey?: boolean
+}
+
+/**
+ * Should this keydown engage space-pan?
+ *
+ * Ignored, and each for its own reason:
+ * - not the space bar;
+ * - a MODIFIED space (⌘Space is the OS switcher, Ctrl/Alt+Space belong to other bindings) — taking
+ * those would break something the user meant for someone else;
+ * - the auto-REPEAT of a held key, so engaging happens once per press rather than sixty times a
+ * second;
+ * - anything typed into a terminal, a note or a field, which is the case that matters most: a
+ * space swallowed there is a wrong character in the user's text, not a missing pan.
+ */
+export function spacePanKeydown(e: SpaceKeyEvent, active: Element | null): SpacePanAction {
+ if (e.key !== ' ' && e.key !== 'Spacebar') return 'ignore'
+ if (e.repeat) return 'ignore'
+ if (e.ctrlKey || e.metaKey || e.altKey) return 'ignore'
+ if (typingTarget(active)) return 'ignore'
+ return 'engage'
+}
+
+/** Is this keyup the release of the space bar? Modifier-blind on purpose: a user who taps ⌘ while
+ * panning still gets a keyup for space, and a pan that never released would strand the canvas in
+ * grab mode. */
+export function isSpaceRelease(e: SpaceKeyEvent): boolean {
+ return e.key === ' ' || e.key === 'Spacebar'
+}