Skip to content

The agent that grows with you

fix(tui): Ctrl+C in /connectors closes the panel without reconnecting

Siddharth Balyanffe20f24ad9b
diff --git a/ui-tui/src/__tests__/connectorAccounts.test.ts b/ui-tui/src/__tests__/connectorAccounts.test.ts
index a6f60919f03..632735a10e3 100644
--- a/ui-tui/src/__tests__/connectorAccounts.test.ts
+++ b/ui-tui/src/__tests__/connectorAccounts.test.ts
@@ -7,7 +7,7 @@ import {
resetConnectionOperationsForTests
} from '../app/connectionOperationStore.js'
import { getOverlayState, hasPromptOpen, patchOverlayState, resetOverlayState } from '../app/overlayStore.js'
-import { accountRowText, accountView, nameProblem } from '../domain/connectorAccounts.js'
+import { accountRowText, accountView, nameProblem, panelShortcut } from '../domain/connectorAccounts.js'
const row = (over: Partial<ConnectorAccountRow> & { disabled?: boolean }): ConnectorAccountRow =>
({
@@ -48,6 +48,15 @@ describe('connector account rows', () => {
})
})
+describe('panel letter shortcuts', () => {
+ it('maps a bare letter to its action and never a Ctrl or Meta chord, so Ctrl+C cancels without reconnecting', () => {
+ expect(panelShortcut('c', { ctrl: false, meta: false })).toBe('reconnect')
+ expect(panelShortcut('c', { ctrl: true, meta: false })).toBeNull()
+ expect(panelShortcut('x', { ctrl: false, meta: true })).toBeNull()
+ expect(panelShortcut('z', {})).toBeNull()
+ })
+})
+
describe('settled connection lines', () => {
afterEach(resetConnectionOperationsForTests)
diff --git a/ui-tui/src/components/connectorsOverlay.tsx b/ui-tui/src/components/connectorsOverlay.tsx
index 31b758b705c..a590bbec851 100644
--- a/ui-tui/src/components/connectorsOverlay.tsx
+++ b/ui-tui/src/components/connectorsOverlay.tsx
@@ -18,7 +18,8 @@ import {
accountView,
isRetired,
nameProblem,
- type NameProblem
+ type NameProblem,
+ panelShortcut
} from '../domain/connectorAccounts.js'
import type { GatewayClient } from '../gatewayClient.js'
import type { Translations } from '../i18n/types.js'
@@ -297,7 +298,9 @@ export function ConnectorsOverlay({ gw, maxWidth, onClose, t }: ConnectorsOverla
: startConnect(row.connector, { connection_id: row.connection_id }, accountName(row))
const listKey = (ch: string, key: KeyLike) => {
- if (key.escape || ch === 'q') {
+ const shortcut = panelShortcut(ch, key)
+
+ if (key.escape || shortcut === 'close') {
return onClose()
}
@@ -313,7 +316,7 @@ export function ConnectorsOverlay({ gw, maxWidth, onClose, t }: ConnectorsOverla
return setShowRetired(value => !value)
}
- if (ch === 'a') {
+ if (shortcut === 'add') {
return openAddApp()
}
@@ -321,13 +324,13 @@ export function ConnectorsOverlay({ gw, maxWidth, onClose, t }: ConnectorsOverla
return
}
- if (ch === 'r') {
+ if (shortcut === 'rename') {
setErr('')
return setStage({ draft: selected.alias ?? '', kind: 'rename', row: selected })
}
- if (ch === 'x') {
+ if (shortcut === 'remove') {
const row = selected
return patchOverlayState({
@@ -339,7 +342,7 @@ export function ConnectorsOverlay({ gw, maxWidth, onClose, t }: ConnectorsOverla
})
}
- if (ch === 'c') {
+ if (shortcut === 'reconnect') {
return reconnect(selected)
}
}
@@ -556,8 +559,10 @@ function LinkView({ footer, stage, t, title, width }: StageViewProps<'link'>) {
}
interface KeyLike {
+ ctrl: boolean
downArrow: boolean
escape: boolean
+ meta: boolean
tab: boolean
upArrow: boolean
}
diff --git a/ui-tui/src/domain/connectorAccounts.ts b/ui-tui/src/domain/connectorAccounts.ts
index 39aa6cfa53c..042d5153e82 100644
--- a/ui-tui/src/domain/connectorAccounts.ts
+++ b/ui-tui/src/domain/connectorAccounts.ts
@@ -35,6 +35,22 @@ export function accountRowText(row: ConnectorAccountRow, statusLabel: string, un
return `${row.connector} · ${name} · ${statusLabel}`
}
+export type PanelShortcut = 'add' | 'close' | 'reconnect' | 'remove' | 'rename'
+
+const PANEL_SHORTCUTS: Readonly<Record<string, PanelShortcut>> = {
+ a: 'add',
+ c: 'reconnect',
+ q: 'close',
+ r: 'rename',
+ x: 'remove'
+}
+
+/** The panel's letter shortcut for a key press. A Ctrl or Meta chord is never one: Ink reports Ctrl+C as `c`
+ * with `ctrl` set, and that press belongs to the global cancel, not to Reconnect. */
+export function panelShortcut(ch: string, key: { ctrl?: boolean; meta?: boolean }): PanelShortcut | null {
+ return key.ctrl || key.meta ? null : (PANEL_SHORTCUTS[ch] ?? null)
+}
+
export type NameProblem = 'invalid' | 'taken' | null
/** Client-side check before a rename or an add; the gateway re-checks and answers alias_taken. */