fix(coding-agent/modes): resolved escape key handling under kitty keyboard protocol

- Update input handler to recognize CSI-u escape sequences using `matchesKey`.
- Ensure legacy bare escape sequences remain supported in environments without the protocol.
- Add test coverage for both CSI-u and legacy escape inputs.
This commit is contained in:
can1357
2026-06-23 00:36:54 +02:00
parent 9569e355b7
commit 2ff005a354
2 changed files with 51 additions and 1 deletions
@@ -11,6 +11,7 @@
import {
Container,
Input,
matchesKey,
type SelectItem,
SelectList,
type SettingItem,
@@ -36,13 +37,18 @@ import { DynamicBorder } from "./dynamic-border";
/**
* Forwards a keystroke to `input`, but cancels via `onCancel` when the user presses Escape.
*
* Escape is decoded via `matchesKey` rather than a raw `\x1b` compare: inside the
* fullscreen settings overlay the kitty keyboard protocol is active (ghostty/kitty),
* where the Escape key arrives as the CSI-u sequence `\x1b[27u`, not a bare `\x1b`.
* The literal fallbacks preserve legacy single/double-escape on terminals without it.
*/
export function handleInputOrEscape(
data: string,
input: { handleInput(data: string): void },
onCancel: () => void,
): void {
if (data === "\x1b" || data === "\x1b\x1b") {
if (data === "\x1b" || data === "\x1b\x1b" || matchesKey(data, "escape")) {
onCancel();
return;
}