The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tui): Ctrl+D exits from an empty composer on macOS too
teknium1b787fb9128a0
diff --git a/ui-tui/src/__tests__/platform.test.ts b/ui-tui/src/__tests__/platform.test.tsindex a5da6985eb5..1cafb4f5c46 100644--- a/ui-tui/src/__tests__/platform.test.ts+++ b/ui-tui/src/__tests__/platform.test.ts@@ -551,6 +551,17 @@ describe('isMacActionFallback', () => {expect(isMacActionFallback({ ctrl: true, meta: false, super: true }, 'w', 'w')).toBe(false)})+ it('routes literal Ctrl+D (terminal EOF) on macOS, where the action modifier is Cmd (#116443)', async () => {+ const { isAction, isMacActionFallback } = await importPlatform('darwin')+ const ctrlD = { ctrl: true, meta: false, super: false }++ // The exit binding used isAction alone: Ctrl+D never matched on macOS, and Ghostty eats Cmd+D.+ expect(isAction(ctrlD, 'd', 'd')).toBe(false)+ expect(isMacActionFallback(ctrlD, 'd', 'd')).toBe(true)+ expect(isMacActionFallback({ ctrl: true, meta: true, super: false }, 'd', 'd')).toBe(false)+ expect(isMacActionFallback({ ctrl: false, meta: false, super: true }, 'd', 'd')).toBe(false)+ })+it('is a no-op on non-macOS (Linux routes Ctrl+K/W through isActionMod directly)', async () => {const { isMacActionFallback } = await importPlatform('linux')diff --git a/ui-tui/src/__tests__/useInputHandlers.test.ts b/ui-tui/src/__tests__/useInputHandlers.test.tsindex 96778fa6359..f429bdc5c5e 100644--- a/ui-tui/src/__tests__/useInputHandlers.test.ts+++ b/ui-tui/src/__tests__/useInputHandlers.test.ts@@ -4,6 +4,7 @@ import { getOverlayState, patchOverlayState, resetOverlayState } from '../app/ovimport { rememberServerRequest, resetServerRequestsForTests } from '../app/serverRequestStore.js'import {applyVoiceRecordResponse,+ composerHasDraft,dismissSensitivePrompt,handleIdleHotkeyExit,resolveCtrlCComposerAction,@@ -52,6 +53,15 @@ describe('shouldFallThroughForScroll — keep transcript scrolling alive during})})+describe('composerHasDraft — Ctrl+D exits only from an empty composer (#116443)', () => {+ it('is false for an empty composer and true for text, multi-line buffer or attachments', () => {+ expect(composerHasDraft({ input: '', inputBuf: [], tokens: [] })).toBe(false)+ expect(composerHasDraft({ input: 'hi', inputBuf: [], tokens: [] })).toBe(true)+ expect(composerHasDraft({ input: '', inputBuf: ['line 1'], tokens: [] })).toBe(true)+ expect(composerHasDraft({ input: '', inputBuf: [], tokens: [{ kind: 'image' }] })).toBe(true)+ })+})+describe('shouldAllowIdleHotkeyExit', () => {it('keeps idle exit hotkeys enabled in normal terminals', () => {expect(shouldAllowIdleHotkeyExit(false)).toBe(true)diff --git a/ui-tui/src/app/useInputHandlers.ts b/ui-tui/src/app/useInputHandlers.tsindex 9b7abb257d6..61d8f1755c8 100644--- a/ui-tui/src/app/useInputHandlers.ts+++ b/ui-tui/src/app/useInputHandlers.ts@@ -6,7 +6,7 @@ import { DASHBOARD_TUI_MODE } from '../config/env.js'import { DOUBLE_ESC_MS, TYPING_IDLE_MS } from '../config/timing.js'import { applyCompletion } from '../domain/slash.js'import type { ConfigSetResponse, VoiceRecordResponse } from '../gatewayTypes.js'-import { isAction, isCopyShortcut, isMac, isVoiceToggleKey } from '../lib/platform.js'+import { isAction, isCopyShortcut, isMac, isMacActionFallback, isVoiceToggleKey } from '../lib/platform.js'import { computePrecisionWheelStep, initPrecisionWheel } from '../lib/precisionWheel.js'import { computeWheelStep, initWheelAccelForHost } from '../lib/wheelAccel.js'import { closeWidget, dispatchWidgetInput } from '../sdk/host.js'@@ -31,6 +31,13 @@ const DASHBOARD_NEW_SESSION_MESSAGE = 'starting a fresh dashboard chat...'export const shouldAllowIdleHotkeyExit = (dashboardTuiMode = DASHBOARD_TUI_MODE) => !dashboardTuiMode+/** Text or attachments in the composer: Ctrl+D must not exit over an unsent draft (#116443). */+export const composerHasDraft = (cState: {+ input: string+ inputBuf: string[]+ tokens?: unknown[]+}): boolean => Boolean(cState.input || cState.inputBuf.length || cState.tokens?.length)+export function handleInputSelectionClipboard(selection: ReturnType<typeof getInputSelection>,action: 'copy' | 'cut'@@ -685,7 +692,9 @@ export function useInputHandlers(ctx: InputHandlerContext): InputHandlerResult {})}- if (isAction(key, ch, 'd')) {+ // Ctrl+D is the terminal EOF convention: exit only from an empty composer, on every+ // platform (macOS's action modifier is Cmd, which Ghostty consumes for split panes).+ if ((isAction(key, ch, 'd') || isMacActionFallback(key, ch, 'd')) && !composerHasDraft(cState)) {return handleIdleHotkeyExit(actions, DASHBOARD_TUI_MODE, () => {gateway.gw.publishLocalEvent({payload: { reason: 'idle_exit_hotkey' },diff --git a/ui-tui/src/lib/platform.ts b/ui-tui/src/lib/platform.tsindex 60f6758684c..e63eb29347f 100644--- a/ui-tui/src/lib/platform.ts+++ b/ui-tui/src/lib/platform.ts@@ -23,11 +23,13 @@ export const isActionMod = (key: { ctrl: boolean; meta: boolean; super?: boolean* - Ctrl+K (kill-to-end) and Ctrl+W (delete-word-back) are standard readline* bindings that users expect to work regardless of platform, even though* no terminal rewrites Cmd into them.+ * - Ctrl+D is the terminal EOF convention (exit on an empty line); Cmd+D is+ * taken by the terminal itself in Ghostty (split pane), so it is no substitute.*/export const isMacActionFallback = (key: { ctrl: boolean; meta: boolean; super?: boolean },ch: string,- target: 'a' | 'e' | 'u' | 'k' | 'w'+ target: 'a' | 'd' | 'e' | 'u' | 'k' | 'w'): boolean => isMac && key.ctrl && !key.meta && key.super !== true && ch.toLowerCase() === target/** Match action-modifier + a single character (case-insensitive). */