Fix Shift+Enter for multiline input in agent terminals

xterm.js sends plain \r for Enter regardless of modifiers. Intercept
modified Enter in the custom key handler so it routes through CSI u
encoding (Kitty keyboard protocol), which Claude Code uses for
Shift+Enter newlines.
This commit is contained in:
Mohamed Boudra
2026-04-12 22:10:16 +07:00
parent 609d11ee8d
commit 0095f61121
3 changed files with 81 additions and 1 deletions
+12 -1
View File
@@ -85,10 +85,21 @@ export function hasPendingTerminalModifiers(modifiers: PendingTerminalModifiers)
export function shouldInterceptDomTerminalKey(args: {
key: string;
ctrlKey: boolean;
shiftKey: boolean;
altKey: boolean;
metaKey: boolean;
pendingModifiers: PendingTerminalModifiers;
}): boolean {
return hasPendingTerminalModifiers(args.pendingModifiers);
if (hasPendingTerminalModifiers(args.pendingModifiers)) {
return true;
}
// xterm.js sends plain \r for Enter regardless of modifiers.
// Intercept modified Enter so it gets CSI u encoding (Kitty keyboard protocol),
// which Claude Code and other TUI apps use for Shift+Enter newlines.
if (args.key === "Enter" && (args.shiftKey || args.ctrlKey || args.altKey || args.metaKey)) {
return true;
}
return false;
}
export function mergeTerminalModifiers(args: {