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): let Space type in the file editor node (#930)

Erik Zwep1818ecdce888
diff --git a/src/renderer/lib/keyContext.test.ts b/src/renderer/lib/keyContext.test.ts
index acbc18790..622dcacf8 100644
--- a/src/renderer/lib/keyContext.test.ts
+++ b/src/renderer/lib/keyContext.test.ts
@@ -2,6 +2,7 @@ import { describe, it, expect } from 'vitest'
import { readFileSync } from 'fs'
import {
XTERM_INPUT_CLASS,
+ hasEditContext,
isTerminalTarget,
isTypingTarget,
keyDispatchContextFor
@@ -9,10 +10,11 @@ import {
const el = (
tagName: string,
- extra: Partial<{ isContentEditable: boolean; classes: string[] }> = {}
+ extra: Partial<{ isContentEditable: boolean; classes: string[]; editContext: unknown }> = {}
) => ({
tagName,
isContentEditable: extra.isContentEditable,
+ editContext: extra.editContext,
classList: { contains: (n: string) => (extra.classes ?? []).includes(n) }
})
@@ -30,6 +32,16 @@ describe('isTypingTarget', () => {
expect(isTypingTarget(el('TEXTAREA'))).toBe(true)
expect(isTypingTarget(el('DIV', { isContentEditable: true }))).toBe(true)
})
+ it('an element with an EditContext attached is typing — the Monaco editor (#930)', () => {
+ // Monaco 0.56 types through `div.native-edit-context` + the EditContext API: no textarea, no
+ // contentEditable. Missing it let canvas shortcuts (⌘T, ⌘⇧A, …) fire from inside an editor.
+ expect(isTypingTarget(el('DIV', { editContext: {} }))).toBe(true)
+ expect(hasEditContext(el('DIV', { editContext: {} }))).toBe(true)
+ // `null` is what an element WITHOUT one reports (and what Monaco sets on dispose).
+ expect(hasEditContext(el('DIV', { editContext: null }))).toBe(false)
+ expect(hasEditContext(el('DIV'))).toBe(false)
+ expect(hasEditContext(null)).toBe(false)
+ })
it('the xterm helper textarea is NOT typing (it is the terminal)', () => {
expect(isTypingTarget(el('TEXTAREA', { classes: [XTERM_INPUT_CLASS] }))).toBe(false)
})
@@ -76,3 +88,20 @@ describe('xterm version pin', () => {
expect(dist.includes(XTERM_INPUT_CLASS)).toBe(true)
})
})
+
+describe('Monaco EditContext pin (#930)', () => {
+ it('the installed Monaco still types through an EditContext, on by default', () => {
+ // Why `hasEditContext` exists at all. If a Monaco upgrade drops the EditContext input (or turns
+ // it off by default) this fails, and the check can be re-evaluated rather than left to rot.
+ const native = readFileSync(
+ 'node_modules/monaco-editor/esm/vs/editor/browser/controller/editContext/native/nativeEditContext.js',
+ 'utf8'
+ )
+ expect(native.includes('.editContext = this._editContext')).toBe(true)
+ const options = readFileSync(
+ 'node_modules/monaco-editor/esm/vs/editor/common/config/editorOptions.js',
+ 'utf8'
+ )
+ expect(/'editContext', true/.test(options)).toBe(true)
+ })
+})
diff --git a/src/renderer/lib/keyContext.ts b/src/renderer/lib/keyContext.ts
index 5a5e9ee03..fc281b32d 100644
--- a/src/renderer/lib/keyContext.ts
+++ b/src/renderer/lib/keyContext.ts
@@ -23,6 +23,8 @@ export const XTERM_INPUT_CLASS = 'xterm-helper-textarea'
export interface ContextElement {
tagName: string
isContentEditable?: boolean
+ /** The element's attached EditContext (`HTMLElement.editContext`); null/absent when it has none. */
+ editContext?: unknown
classList?: { contains(name: string): boolean }
/** DOM ancestry, when the element has it (a real Element does); absent = no ancestry answer. */
closest?(selector: string): unknown
@@ -45,13 +47,32 @@ export function isTerminalTarget(el: ContextElement | null): boolean {
return el?.classList?.contains(XTERM_INPUT_CLASS) === true
}
+/**
+ * Does this element take text through the EditContext API? Issue #930.
+ *
+ * The third kind of text surface, next to a field and a contentEditable, and the one every
+ * `tagName` check misses: an element with an EditContext attached is a plain `<div>` that the
+ * browser feeds text input to directly. Monaco 0.56 switched to it BY DEFAULT wherever the API
+ * exists (`editContext: true`, gated on `typeof EditContext === 'function'`, which Electron's
+ * Chromium passes), so a focused editor node is no longer Monaco's old hidden `<textarea>` but a
+ * `div.native-edit-context` with `isContentEditable === false`. Space-to-pan took every space
+ * typed there, and the canvas shortcuts stopped standing down inside the editor.
+ *
+ * Asked of the web-platform property rather than Monaco's class name on purpose: the property is
+ * what makes the element a text surface, so any other EditContext-based input is covered too.
+ * `keyContext.test.ts` pins that the installed Monaco still attaches one.
+ */
+export function hasEditContext(el: ContextElement | null): boolean {
+ return el?.editContext != null
+}
+
/** True when the keystroke belongs to text the user is editing. The xterm textarea is
* deliberately excluded — a focused terminal is `terminal`, never `typing`, and the two
* must stay disjoint (see KeyDispatchContext). */
export function isTypingTarget(el: ContextElement | null): boolean {
if (!el || isTerminalTarget(el)) return false
if (el.tagName === 'INPUT' || el.tagName === 'TEXTAREA') return true
- return el.isContentEditable === true
+ return el.isContentEditable === true || hasEditContext(el)
}
/** `terminalFirst` is REQUIRED, not defaulted: it is a user policy, and a default here would let
diff --git a/src/renderer/lib/paneFocus.test.ts b/src/renderer/lib/paneFocus.test.ts
index f68abebaa..7a116d5b2 100644
--- a/src/renderer/lib/paneFocus.test.ts
+++ b/src/renderer/lib/paneFocus.test.ts
@@ -17,6 +17,15 @@ describe('shouldReleasePaneFocus', () => {
expect(shouldReleasePaneFocus(el('DIV', true))).toBe(true)
})
+ it('releases a Monaco editor too — its input is an EditContext div, not a textarea (#930)', () => {
+ const monacoInput = {
+ tagName: 'DIV',
+ isContentEditable: false,
+ editContext: {}
+ } as unknown as Element
+ expect(shouldReleasePaneFocus(monacoInput)).toBe(true)
+ })
+
it('leaves anything else alone', () => {
// Blurring a focused button or node div would fight the browser's own focus handling for no
// gain: neither of them eats a keystroke.
diff --git a/src/renderer/lib/paneFocus.ts b/src/renderer/lib/paneFocus.ts
index 2c6219d69..446403fdf 100644
--- a/src/renderer/lib/paneFocus.ts
+++ b/src/renderer/lib/paneFocus.ts
@@ -1,3 +1,5 @@
+import { hasEditContext } from './keyContext'
+
/**
* Should a click on the EMPTY canvas take the keyboard away from `active`?
*
@@ -12,7 +14,8 @@
*
* True only for a real EDITING surface. A button or a node div that happens to be focused is
* harmless and blurring it would fight the browser's own focus handling; a `textarea`, an `input`
- * or a `contenteditable` is the one that swallows typing.
+ * or a `contenteditable` is the one that swallows typing — and so is an element with an EditContext
+ * attached, which is what a focused Monaco editor is since 0.56 (issue #930, see `hasEditContext`).
*
* `null`/`body` is the already-correct state and answers false, so the common click costs nothing.
*/
@@ -20,5 +23,5 @@ export function shouldReleasePaneFocus(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
+ return (active as HTMLElement).isContentEditable === true || hasEditContext(active)
}
diff --git a/src/renderer/lib/spacePan.test.ts b/src/renderer/lib/spacePan.test.ts
index b681a39c9..25620ee25 100644
--- a/src/renderer/lib/spacePan.test.ts
+++ b/src/renderer/lib/spacePan.test.ts
@@ -28,6 +28,20 @@ describe('spacePanKeydown', () => {
expect(typingTarget(el('TEXTAREA'))).toBe(true)
})
+ it('leaves the Monaco EDITOR alone — it types through an EditContext, not a textarea (#930)', () => {
+ // Monaco 0.56 turns `editContext` on by default wherever the browser has the API (Electron's
+ // Chromium does), and then the focused element is a plain `div.native-edit-context` with an
+ // EditContext attached: not a TEXTAREA, not contentEditable. Every space typed in an editor
+ // node was being taken for panning.
+ const monacoInput = {
+ tagName: 'DIV',
+ isContentEditable: false,
+ editContext: {}
+ } as unknown as Element
+ expect(typingTarget(monacoInput)).toBe(true)
+ expect(spacePanKeydown({ key: ' ' }, monacoInput)).toBe('ignore')
+ })
+
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')
diff --git a/src/renderer/lib/spacePan.ts b/src/renderer/lib/spacePan.ts
index 892a72cdb..200c48614 100644
--- a/src/renderer/lib/spacePan.ts
+++ b/src/renderer/lib/spacePan.ts
@@ -5,6 +5,7 @@
* decisions live here because the failure modes are all about WHEN it may engage, and every one of
* them is testable without a DOM.
*/
+import { hasEditContext } from './keyContext'
/** What a space keydown should do. */
export type SpacePanAction = 'engage' | 'ignore'
@@ -18,12 +19,14 @@ export type SpacePanAction = 'engage' | 'ignore'
*
* 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.
+ * Monaco is NOT a textarea any more (issue #930): it types through an EditContext, which
+ * `hasEditContext` recognises — without it, every space typed in an editor node became a pan.
*/
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
+ return (active as HTMLElement).isContentEditable === true || hasEditContext(active)
}
/** The event shape this reads — a `KeyboardEvent` satisfies it, and so does a test literal. */