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(editor): keep React Flow's key handling out of Monaco (#930)

Erik Zwep607db1f2a0ae
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 237a224c6..9f3e12a5f 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -14993,6 +14993,12 @@ export function Canvas() {
// node's is "frame this node", so d3's zoom-in would fight both.
zoomOnDoubleClick={false}
zoomActivationKeyCode={null}
+ // Off: space-to-pan is the canvas's OWN gesture (lib/spacePan.ts, issue #86), which drives
+ // `panOnDrag` above through the `spacePan` state. React Flow's built-in duplicate (default
+ // 'Space') was a second window listener with a narrower idea of a text surface: it cannot
+ // see Monaco's EditContext input, so it preventDefault-ed every space typed in an editor
+ // node (#930). It also forced panOnDrag/panOnScroll on while held, straight past the lock.
+ panActivationKeyCode={null}
snapToGrid={settings.snapToGrid}
snapGrid={[settings.gridSize, settings.gridSize]}
>
diff --git a/src/renderer/lib/keyContext.test.ts b/src/renderer/lib/keyContext.test.ts
index 622dcacf8..237efbc2f 100644
--- a/src/renderer/lib/keyContext.test.ts
+++ b/src/renderer/lib/keyContext.test.ts
@@ -1,5 +1,6 @@
import { describe, it, expect } from 'vitest'
import { readFileSync } from 'fs'
+import { isInputDOMNode } from '@xyflow/system'
import {
XTERM_INPUT_CLASS,
hasEditContext,
@@ -105,3 +106,33 @@ describe('Monaco EditContext pin (#930)', () => {
expect(/'editContext', true/.test(options)).toBe(true)
})
})
+
+describe("React Flow's own key handling vs the Monaco editor (#930)", () => {
+ // React Flow runs key handlers of its own (the node wrapper's arrow-key move, its key-press
+ // hooks), and they stand down only for what `isInputDOMNode` recognises: an INPUT/SELECT/TEXTAREA,
+ // a `contenteditable` ATTRIBUTE, or anything inside `.nokey`. Monaco's EditContext div is none of
+ // the first three, so the Monaco mounts carry `nokey`.
+ const editContextDiv = (insideNokey: boolean) => ({
+ nodeType: 1,
+ nodeName: 'DIV',
+ editContext: {},
+ hasAttribute: () => false,
+ closest: (sel: string) => (insideNokey && sel === '.nokey' ? {} : null)
+ })
+ const keyEvent = (target: unknown) => ({ target }) as unknown as KeyboardEvent
+
+ it('an EditContext div is NOT an input to React Flow on its own', () => {
+ expect(isInputDOMNode(keyEvent(editContextDiv(false)))).toBe(false)
+ })
+
+ it('…and IS one inside `.nokey`', () => {
+ expect(isInputDOMNode(keyEvent(editContextDiv(true)))).toBe(true)
+ })
+
+ it('every Monaco mount carries `nokey`', () => {
+ for (const file of ['src/renderer/nodes/EditorNode.tsx', 'src/renderer/nodes/DiffNode.tsx']) {
+ const source = readFileSync(file, 'utf8')
+ expect(source, file).toMatch(/className="[^"]*\bnokey\b[^"]*"\s+ref=\{bodyRef\}/)
+ }
+ })
+})
diff --git a/src/renderer/lib/spacePan.test.ts b/src/renderer/lib/spacePan.test.ts
index 25620ee25..1f69e5258 100644
--- a/src/renderer/lib/spacePan.test.ts
+++ b/src/renderer/lib/spacePan.test.ts
@@ -1,3 +1,4 @@
+import { readFileSync } from 'fs'
import { describe, expect, it } from 'vitest'
import { isSpaceRelease, spacePanKeydown, typingTarget } from './spacePan'
@@ -76,3 +77,13 @@ describe('isSpaceRelease', () => {
expect(isSpaceRelease({ key: 'a' })).toBe(false)
})
})
+
+describe("React Flow's built-in space-pan (#930)", () => {
+ it('is switched off, so this module is the only space-to-pan', () => {
+ // React Flow's default `panActivationKeyCode` is 'Space'. Its listener cannot see an EditContext
+ // target (so it swallowed spaces typed in the Monaco editor) and it forces panOnDrag on, past the
+ // canvas lock.
+ const source = readFileSync('src/renderer/canvas/Canvas.tsx', 'utf8')
+ expect(source).toContain('panActivationKeyCode={null}')
+ })
+})
diff --git a/src/renderer/nodes/DiffNode.tsx b/src/renderer/nodes/DiffNode.tsx
index 381e41026..6aff2c7a9 100644
--- a/src/renderer/nodes/DiffNode.tsx
+++ b/src/renderer/nodes/DiffNode.tsx
@@ -170,7 +170,9 @@ export function DiffNode({ id, data, selected }: NodeProps<CanvasNode>) {
</div>
</div>
) : (
- <div className="editor-node__body nodrag nowheel" ref={bodyRef} />
+ // `nokey`: keeps React Flow's key handling (arrow-key node move, key-press hooks) out of
+ // Monaco, whose EditContext input React Flow does not recognise as one (#930).
+ <div className="editor-node__body nodrag nowheel nokey" ref={bodyRef} />
)}
</div>
)
diff --git a/src/renderer/nodes/EditorNode.tsx b/src/renderer/nodes/EditorNode.tsx
index 037f74f64..5805e5281 100644
--- a/src/renderer/nodes/EditorNode.tsx
+++ b/src/renderer/nodes/EditorNode.tsx
@@ -354,7 +354,10 @@ export function EditorNode({ id, data, selected }: NodeProps<CanvasNode>) {
</div>
) : (
<>
- <div className="editor-node__monaco nodrag nowheel" ref={bodyRef} />
+ {/* `nokey`: React Flow's own key handling (the selected node's arrow-key move, its
+ key-press hooks) stands down only for inputs, a contenteditable attribute or
+ `.nokey` — and Monaco types through an EditContext div, none of those (#930). */}
+ <div className="editor-node__monaco nodrag nowheel nokey" ref={bodyRef} />
{preview && (
<div className="term-md nodrag nowheel">
<div className="term-md__bar">