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.

fix(canvas): a lost Cmd/Ctrl keyup no longer strands terminals behind the hover guard

reviewcedead7754fb
diff --git a/src/renderer/lib/zoomModifier.test.ts b/src/renderer/lib/zoomModifier.test.ts
new file mode 100644
index 000000000..09b157aa4
--- /dev/null
+++ b/src/renderer/lib/zoomModifier.test.ts
@@ -0,0 +1,53 @@
+// @vitest-environment jsdom
+import { beforeEach, describe, expect, it, vi } from 'vitest'
+
+// The module keeps one window-level latch, so every test loads a fresh copy of it.
+let isZoomModifierHeld: () => boolean
+beforeEach(async () => {
+ vi.resetModules()
+ ;({ isZoomModifierHeld } = await import('./zoomModifier'))
+ isZoomModifierHeld() // installs the listeners
+})
+
+const key = (type: 'keydown' | 'keyup', init: KeyboardEventInit) =>
+ window.dispatchEvent(new KeyboardEvent(type, init))
+
+describe('zoom modifier latch', () => {
+ it('is held from the modifier keydown to its keyup', () => {
+ key('keydown', { key: 'Meta', metaKey: true })
+ expect(isZoomModifierHeld()).toBe(true)
+ key('keyup', { key: 'Meta' })
+ expect(isZoomModifierHeld()).toBe(false)
+ })
+
+ // The stuck "pan mode" after a macOS Space switch: the modifier's keyup went to another app and
+ // no window blur arrived to clear it, so every terminal's hover guard stayed up (the dwell waits
+ // while the modifier is held) until an unrelated key — Escape — was released.
+ it('a pointer event without the modifier clears a latch whose keyup was lost', () => {
+ key('keydown', { key: 'Meta', metaKey: true })
+ window.dispatchEvent(new MouseEvent('mousemove', { metaKey: false, ctrlKey: false }))
+ expect(isZoomModifierHeld()).toBe(false)
+ })
+
+ it('a wheel event reports the live state too', () => {
+ key('keydown', { key: 'Control', ctrlKey: true })
+ window.dispatchEvent(new WheelEvent('wheel', { ctrlKey: false }))
+ expect(isZoomModifierHeld()).toBe(false)
+ })
+
+ it('a pointer event WITH the modifier keeps (or sets) it held — Cmd+wheel over a terminal still zooms', () => {
+ window.dispatchEvent(new WheelEvent('wheel', { metaKey: true }))
+ expect(isZoomModifierHeld()).toBe(true)
+ window.dispatchEvent(new MouseEvent('mousemove', { ctrlKey: true }))
+ expect(isZoomModifierHeld()).toBe(true)
+ })
+
+ it('window blur and focus both clear it', () => {
+ key('keydown', { key: 'Meta', metaKey: true })
+ window.dispatchEvent(new Event('blur'))
+ expect(isZoomModifierHeld()).toBe(false)
+ key('keydown', { key: 'Meta', metaKey: true })
+ window.dispatchEvent(new Event('focus'))
+ expect(isZoomModifierHeld()).toBe(false)
+ })
+})
diff --git a/src/renderer/lib/zoomModifier.ts b/src/renderer/lib/zoomModifier.ts
index 5f1605d07..518b42575 100644
--- a/src/renderer/lib/zoomModifier.ts
+++ b/src/renderer/lib/zoomModifier.ts
@@ -1,6 +1,14 @@
// Tracks whether a zoom modifier (Cmd/Ctrl) is currently held, via a single set of
// capture-phase window listeners. Used by the terminal hover-guard so Cmd+wheel zooming over
// a terminal doesn't dwell-focus (enter) the terminal — the canvas keeps zooming instead.
+//
+// A key latch is only as good as its keyup, and keyups get lost: switch macOS Spaces (a
+// four-finger swipe) and the modifier's release can land in another app with no window blur to
+// clear the latch here. A stuck `true` is not harmless — the hover guard's dwell waits for as long
+// as the modifier is held, so every terminal stays behind its guard (scroll pans the canvas, a
+// click never focuses) until some unrelated key is released. So every pointer and wheel event
+// re-reads the modifier state the OS attached to it: the first mouse movement after coming back
+// corrects the latch, and nothing that was really held is ever dropped.
let held = false
let inited = false
@@ -14,9 +22,18 @@ function ensure(): void {
if (e.key === 'Meta' || e.key === 'Control') held = false
else if (!e.metaKey && !e.ctrlKey) held = false
}
+ const live = (e: MouseEvent) => {
+ held = e.metaKey || e.ctrlKey
+ }
+ const reset = () => (held = false)
window.addEventListener('keydown', down, true)
window.addEventListener('keyup', up, true)
- window.addEventListener('blur', () => (held = false))
+ // WheelEvent is a MouseEvent, so all three carry the live modifier flags.
+ window.addEventListener('mousemove', live, true)
+ window.addEventListener('mousedown', live, true)
+ window.addEventListener('wheel', live, { capture: true, passive: true })
+ window.addEventListener('blur', reset)
+ window.addEventListener('focus', reset)
}
/** True while Cmd or Ctrl is currently pressed. */