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.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
feat(chat): Page Up / Page Down scroll the ⌘M chat view
Paul Robertsonc2a10adbfa19
diff --git a/src/renderer/components/ClosedTranscriptDialog.test.tsx b/src/renderer/components/ClosedTranscriptDialog.test.tsxnew file mode 100644index 000000000..2021c635c--- /dev/null+++ b/src/renderer/components/ClosedTranscriptDialog.test.tsx@@ -0,0 +1,86 @@+// @vitest-environment jsdom+import { act } from 'react'+import { createRoot, type Root } from 'react-dom/client'+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'+import type { ClosedSessionEntry } from '@shared/types'+import { CHAT_PAGE_FRACTION } from '../lib/chatPageKeys'++;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true++// The real panel reads a transcript; this test is about the dialog's keyboard, so a stand-in+// draws only the thread scroller the dialog pages.+vi.mock('../nodes/ChatPanel', () => ({+ ChatPanel: () => (+ <div className="term-chat">+ <div className="term-chat__msgs" />+ </div>+ )+}))++import { ClosedTranscriptDialog } from './ClosedTranscriptDialog'++const entry: ClosedSessionEntry = {+ id: 'c1',+ closedAt: 0,+ node: { id: 'n1', kind: 'terminal', title: 'Closed', agentId: 'claude' } as ClosedSessionEntry['node'],+ absolutePosition: { x: 0, y: 0 },+ sessionId: 's1'+}++let host: HTMLDivElement+let root: Root++beforeEach(() => {+ host = document.createElement('div')+ document.body.appendChild(host)+ root = createRoot(host)+})+afterEach(async () => {+ await act(async () => root.unmount())+ host.remove()+})++async function renderDialog(): Promise<{ box: HTMLElement; thread: HTMLElement; top: () => number }> {+ await act(async () => {+ root.render(<ClosedTranscriptDialog entry={entry} onClose={() => {}} />)+ })+ const box = document.querySelector('.closed-transcript') as HTMLElement+ const thread = document.querySelector('.term-chat__msgs') as HTMLElement+ let top = 2000+ Object.defineProperty(thread, 'clientHeight', { configurable: true, value: 400 })+ Object.defineProperty(thread, 'scrollTop', {+ configurable: true,+ get: () => top,+ set: (v: number) => {+ top = v+ }+ })+ return { box, thread, top: () => top }+}++describe('ClosedTranscriptDialog keyboard', () => {+ it('pages the transcript while the dialog box holds the keyboard', async () => {+ const { box, top } = await renderDialog()+ const e = new KeyboardEvent('keydown', { key: 'PageUp', bubbles: true, cancelable: true })++ await act(async () => {+ box.dispatchEvent(e)+ })++ expect(document.activeElement).toBe(box)+ expect(e.defaultPrevented).toBe(true)+ expect(top()).toBe(2000 - 400 * CHAT_PAGE_FRACTION)+ })++ it('does not page twice when the panel inside already handled the key', async () => {+ const { thread, top } = await renderDialog()+ const e = new KeyboardEvent('keydown', { key: 'PageDown', bubbles: true, cancelable: true })+ e.preventDefault()++ await act(async () => {+ thread.dispatchEvent(e)+ })++ expect(top()).toBe(2000)+ })+})diff --git a/src/renderer/components/ClosedTranscriptDialog.tsx b/src/renderer/components/ClosedTranscriptDialog.tsxindex 72792e4dc..af46eba42 100644--- a/src/renderer/components/ClosedTranscriptDialog.tsx+++ b/src/renderer/components/ClosedTranscriptDialog.tsx@@ -4,6 +4,7 @@ import { useDialogStack } from './dialog-stack'import type { ClosedSessionEntry } from '@shared/types'import { closedTranscriptTarget } from '../lib/closedHistory'import { ChatPanelFallback } from '../nodes/ChatPanelFallback'+import { chatPageDirection, pageChatThread } from '../lib/chatPageKeys'// Same code split as the ⌘M panel on a terminal node: the transcript reader and the markdown// renderer are not on the path to painting a canvas, and this dialog opens on a click.@@ -48,7 +49,17 @@ export function ClosedTranscriptDialog({ entry, onClose }: ClosedTranscriptDialoif (e.key === 'Escape' && isTop()) {e.preventDefault()onClose()+ return}+ // The box holds the keyboard, not the panel inside it, so the panel's own Page Up /+ // Page Down handler never sees these keys here. A key the panel already used is+ // defaultPrevented.+ if (e.defaultPrevented || !(e.target instanceof Element)) return+ const direction = chatPageDirection(e, e.target)+ const thread = boxRef.current?.querySelector<HTMLElement>('.term-chat__msgs')+ if (direction === null || !thread) return+ e.preventDefault()+ pageChatThread(thread, direction)}}>{target.ok ? (diff --git a/src/renderer/lib/chatPageKeys.test.ts b/src/renderer/lib/chatPageKeys.test.tsnew file mode 100644index 000000000..b2469d2f1--- /dev/null+++ b/src/renderer/lib/chatPageKeys.test.ts@@ -0,0 +1,102 @@+// @vitest-environment jsdom+import { describe, expect, it } from 'vitest'+import { CHAT_PAGE_FRACTION, chatPageDirection, pageChatThread, type PageKeyEvent } from './chatPageKeys'++const key = (k: string, mods: Partial<PageKeyEvent> = {}): PageKeyEvent => ({+ key: k,+ altKey: false,+ ctrlKey: false,+ metaKey: false,+ shiftKey: false,+ ...mods+})++function el(html: string): Element {+ const host = document.createElement('div')+ host.innerHTML = html+ return host.firstElementChild as Element+}++describe('chatPageDirection', () => {+ it('pages up and down from a plain element', () => {+ const target = el('<button>Copy</button>')++ const up = chatPageDirection(key('PageUp'), target)+ const down = chatPageDirection(key('PageDown'), target)++ expect(up).toBe(-1)+ expect(down).toBe(1)+ })++ it('pages from the composer while its completion menu is closed', () => {+ const composer = el('<textarea class="term-chat__composer-input" aria-expanded="false"></textarea>')++ const direction = chatPageDirection(key('PageDown'), composer)++ expect(direction).toBe(1)+ })++ it('leaves the keys to the composer while its completion menu is open', () => {+ const composer = el('<textarea class="term-chat__composer-input" aria-expanded="true"></textarea>')++ const direction = chatPageDirection(key('PageUp'), composer)++ expect(direction).toBeNull()+ })++ it.each([+ ['the plan "Revise…" textarea', '<textarea class="term-chat__input"></textarea>'],+ ['a question "Other" input', '<input class="term-chat__input" />'],+ ['a select', '<select></select>']+ ])('leaves the keys to %s', (_name, html) => {+ const target = el(html)++ const direction = chatPageDirection(key('PageUp'), target)++ expect(direction).toBeNull()+ })++ it('leaves the keys to editable content', () => {+ const target = el('<div contenteditable="true"></div>') as HTMLElement+ // jsdom does not derive isContentEditable from the attribute.+ Object.defineProperty(target, 'isContentEditable', { value: true })++ const direction = chatPageDirection(key('PageUp'), target)++ expect(direction).toBeNull()+ })++ it.each(['altKey', 'ctrlKey', 'metaKey', 'shiftKey'] as const)('ignores Page Up with %s held', (mod) => {+ const target = el('<button>Copy</button>')++ const direction = chatPageDirection(key('PageUp', { [mod]: true }), target)++ expect(direction).toBeNull()+ })++ it('ignores other keys', () => {+ const target = el('<button>Copy</button>')++ const direction = chatPageDirection(key('ArrowUp'), target)++ expect(direction).toBeNull()+ })+})++describe('pageChatThread', () => {+ it('moves the scroller by the page fraction of its height', () => {+ const scroller = document.createElement('div')+ let top = 1000+ Object.defineProperty(scroller, 'clientHeight', { value: 400 })+ Object.defineProperty(scroller, 'scrollTop', {+ get: () => top,+ set: (v: number) => {+ top = v+ }+ })++ pageChatThread(scroller, -1)++ expect(top).toBe(1000 - 400 * CHAT_PAGE_FRACTION)+ })+})diff --git a/src/renderer/lib/chatPageKeys.ts b/src/renderer/lib/chatPageKeys.tsnew file mode 100644index 000000000..aab400352--- /dev/null+++ b/src/renderer/lib/chatPageKeys.ts@@ -0,0 +1,47 @@+/**+ * Page Up / Page Down in the ⌘M chat view scroll the CONVERSATION.+ *+ * The keyboard normally sits in the composer (a two-row textarea), so without this the keys only+ * moved the caret inside the draft and the thread could not be paged at all: the message list is+ * a scroller nobody focuses. Slack and claude.ai route these keys the same way.+ *+ * A control that uses the keys itself keeps them: any other text field (the plan's "Revise…" box,+ * a question's "Other" input), a `<select>`, editable content, and the composer while its `/` / `@`+ * completion menu is open.+ */++/** Chromium's own page step: 87.5% of the viewport, so a line of context carries over. */+export const CHAT_PAGE_FRACTION = 0.875++/** The composer's textarea class (ChatComposer.tsx). */+const COMPOSER_CLASS = 'term-chat__composer-input'++export interface PageKeyEvent {+ key: string+ altKey: boolean+ ctrlKey: boolean+ metaKey: boolean+ shiftKey: boolean+}++/** -1 (up) / 1 (down) when this key pages the thread from `target`, else null. */+export function chatPageDirection(e: PageKeyEvent, target: Element | null): -1 | 1 | null {+ if (e.key !== 'PageUp' && e.key !== 'PageDown') return null+ if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) return null+ if (target !== null && ownsPageKeys(target)) return null+ return e.key === 'PageUp' ? -1 : 1+}++function ownsPageKeys(target: Element): boolean {+ if (target instanceof HTMLElement && target.isContentEditable) return true+ const tag = target.tagName+ if (tag === 'SELECT') return true+ if (tag !== 'TEXTAREA' && tag !== 'INPUT') return false+ if (!target.classList.contains(COMPOSER_CLASS)) return true+ return target.getAttribute('aria-expanded') === 'true'+}++/** Scroll the thread by one page. The scroller's own scroll event then does the bookkeeping. */+export function pageChatThread(scroller: HTMLElement, direction: -1 | 1): void {+ scroller.scrollTop += direction * Math.round(scroller.clientHeight * CHAT_PAGE_FRACTION)+}diff --git a/src/renderer/nodes/ChatPanel.paging.test.tsx b/src/renderer/nodes/ChatPanel.paging.test.tsxindex 416164f06..b1a623d31 100644--- a/src/renderer/nodes/ChatPanel.paging.test.tsx+++ b/src/renderer/nodes/ChatPanel.paging.test.tsx@@ -369,3 +369,44 @@ describe('ChatPanel progressive loading', () => {expect(host.textContent).toContain("Couldn't read the transcript.")})})++describe('ChatPanel Page Up / Page Down', () => {+ const press = async (target: Element, key: string): Promise<KeyboardEvent> => {+ const e = new KeyboardEvent('keydown', { key, bubbles: true, cancelable: true })+ await act(async () => {+ target.dispatchEvent(e)+ })+ return e+ }+ const composer = (): HTMLTextAreaElement =>+ host.querySelector('.term-chat__composer-input') as HTMLTextAreaElement++ it('pages the thread from the composer', async () => {+ await render()+ await settle(0, { messages: [say(0, 'a'), say(10, 'b'), say(20, 'c')] })+ const bottom = msgs().scrollTop++ const up = await press(composer(), 'PageUp')++ expect(up.defaultPrevented).toBe(true)+ expect(msgs().scrollTop).toBe(bottom - 350)++ await press(composer(), 'PageDown')++ expect(msgs().scrollTop).toBe(bottom)+ })++ it('leaves Shift+Page Up to the composer (selection), without scrolling the thread', async () => {+ await render()+ await settle(0, { messages: [say(0, 'a'), say(10, 'b'), say(20, 'c')] })+ const bottom = msgs().scrollTop+ const e = new KeyboardEvent('keydown', { key: 'PageUp', shiftKey: true, bubbles: true, cancelable: true })++ await act(async () => {+ composer().dispatchEvent(e)+ })++ expect(e.defaultPrevented).toBe(false)+ expect(msgs().scrollTop).toBe(bottom)+ })+})diff --git a/src/renderer/nodes/ChatPanel.tsx b/src/renderer/nodes/ChatPanel.tsxindex 34ddd0a71..41ebe12cd 100644--- a/src/renderer/nodes/ChatPanel.tsx+++ b/src/renderer/nodes/ChatPanel.tsx@@ -1,6 +1,6 @@import { TEXT_NOT_SUBMITTED, isChatPromptBlocked } from '@shared/text-delivery'import { claudeScreenBlocksInput, readClaudeScreen } from '@shared/agents/claude-screen'-import { memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'+import { memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, type KeyboardEvent } from 'react'import { renderMarkdown } from '../lib/markdown'import { useAgentStatus } from '../state/agentStatus'import { useSession } from '../session/session'@@ -56,6 +56,7 @@ import { ChatTurnActions } from './ChatTurnActions'import { useCodeBlockCopy } from './CodeBlockCopy'import { assistantTurnEnds } from '../lib/chatThread'import { FALLBACK_SESSION_NOTE, transcriptReadCwd } from '../lib/transcriptSession'+import { chatPageDirection, pageChatThread } from '../lib/chatPageKeys'// Memoized bubble: marked+DOMPurify re-ran for EVERY message on each ChatPanel render (each// turn-finish reload, each keystroke re-render). Text is stable per message, so cache per text.@@ -805,6 +806,17 @@ export function ChatPanel({maybeLoadOlder()}+ // Page Up / Page Down page the thread from anywhere in the panel, the composer included+ // (lib/chatPageKeys.ts). `contains`: a React portal's keydown bubbles here too.+ const onPageKey = (e: KeyboardEvent<HTMLDivElement>) => {+ const el = msgsRef.current+ if (!el || e.defaultPrevented || !(e.target instanceof Element) || !e.currentTarget.contains(e.target)) return+ const direction = chatPageDirection(e, e.target)+ if (direction === null) return+ e.preventDefault()+ pageChatThread(el, direction)+ }+// The optimistic bubbles sent into the CLI's queue mid-turn, drawn as "Queued" until the transcript// has them. Object identity is enough: `applyTail` carries an unconfirmed send as the same object.const queuedRef = useRef(new WeakSet<ChatMessage>())@@ -955,7 +967,7 @@ export function ChatPanel({return (// `data-chat-node-id`: which node's chat view this is — the mics that name only a node ask it// (lib/chatComposerDictation.ts `dictationTargetForNode`) so a take never reaches the hidden pane.- <div className="term-chat nodrag nowheel" data-chat-node-id={nodeId}>+ <div className="term-chat nodrag nowheel" data-chat-node-id={nodeId} onKeyDown={onPageKey}><div className="term-chat__bar"><span>{title ?? 'Chat'}</span><span className="term-chat__bar-end">