diff --git a/src/renderer/src/components/terminal-pane/terminal-keyboard-protocol.test.ts b/src/renderer/src/components/terminal-pane/terminal-keyboard-protocol.test.ts new file mode 100644 index 000000000..27ed9c621 --- /dev/null +++ b/src/renderer/src/components/terminal-pane/terminal-keyboard-protocol.test.ts @@ -0,0 +1,40 @@ +import { describe, expect, it } from 'vitest' +import { shouldDisableKittyKeyboardForTerminal } from './terminal-keyboard-protocol' + +describe('shouldDisableKittyKeyboardForTerminal', () => { + it('disables Kitty keyboard for local Windows terminals', () => { + expect( + shouldDisableKittyKeyboardForTerminal({ + userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)', + connectionId: null + }) + ).toBe(true) + }) + + it('keeps Kitty keyboard enabled for SSH terminals from Windows clients', () => { + expect( + shouldDisableKittyKeyboardForTerminal({ + userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)', + connectionId: 'ssh-target-1' + }) + ).toBe(false) + }) + + it('keeps Kitty keyboard enabled on non-Windows clients', () => { + expect( + shouldDisableKittyKeyboardForTerminal({ + userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)', + connectionId: null + }) + ).toBe(false) + }) + + it('keeps Kitty keyboard enabled until connection state is known', () => { + expect( + shouldDisableKittyKeyboardForTerminal({ + userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)', + connectionId: undefined + }) + ).toBe(false) + }) +}) diff --git a/src/renderer/src/components/terminal-pane/terminal-keyboard-protocol.ts b/src/renderer/src/components/terminal-pane/terminal-keyboard-protocol.ts new file mode 100644 index 000000000..a5175b647 --- /dev/null +++ b/src/renderer/src/components/terminal-pane/terminal-keyboard-protocol.ts @@ -0,0 +1,9 @@ +export function shouldDisableKittyKeyboardForTerminal(args: { + userAgent: string + connectionId: string | null | undefined +}): boolean { + // Why: Windows local PTYs run through ConPTY, where some native CLIs do not + // handle xterm's Kitty-enhanced key sequences. SSH terminals keep the + // enhanced protocol for remotes that understand it. + return args.userAgent.includes('Windows') && args.connectionId === null +} diff --git a/src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts b/src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts index 42dbc0baa..3a8547b67 100644 --- a/src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts +++ b/src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts @@ -51,6 +51,7 @@ import { isPrimarySelectionEnabled, setPrimarySelectionText } from '@/lib/primary-selection' +import { getConnectionId } from '@/lib/connection-context' import { SPLIT_TERMINAL_PANE_EVENT, CLOSE_TERMINAL_PANE_EVENT, @@ -58,6 +59,7 @@ import { type CloseTerminalPaneDetail } from '@/constants/terminal' import { acquireWebviewsDragPassthrough } from '../browser-pane/webview-registry' +import { shouldDisableKittyKeyboardForTerminal } from './terminal-keyboard-protocol' type UseTerminalPaneLifecycleDeps = { tabId: string @@ -795,6 +797,10 @@ export function useTerminalPaneLifecycle({ const currentSettings = settingsRef.current const terminalFontWeights = resolveTerminalFontWeights(currentSettings?.terminalFontWeight) const cursorStyle = currentSettings?.terminalCursorStyle ?? 'bar' + const disableKittyKeyboard = shouldDisableKittyKeyboardForTerminal({ + userAgent: navigator.userAgent, + connectionId: getConnectionId(worktreeId) + }) return { fontSize: currentSettings?.terminalFontSize ?? 14, fontFamily: buildFontFamily(currentSettings?.terminalFontFamily ?? ''), @@ -811,6 +817,9 @@ export function useTerminalPaneLifecycle({ cursorInactiveStyle: resolveTerminalCursorInactiveStyle(cursorStyle), cursorBlink: currentSettings?.terminalCursorBlink ?? true, macOptionIsMeta: effectiveMacOptionAsAltRef.current === 'true', + vtExtensions: { + kittyKeyboard: !disableKittyKeyboard + }, lineHeight: currentSettings?.terminalLineHeight ?? 1, wordSeparator: currentSettings?.terminalWordSeparator }