Recover Vim escape input in legacy terminals (#42584)

## Why

Legacy terminals encode `Alt` plus a character the same way as `Esc` followed
by that character. In Vim insert or replace mode, typing a command immediately
after `Esc` could therefore leave the composer in the wrong mode.

## What changed

Recover ambiguous input as separate `Esc` and character events when Vim mode
can consume the escape. Preserve active `Alt` bindings, key chords, image
paste, agent navigation, enhanced-key terminals, and AltGr input.

## Testing

Add coverage for recovered Vim commands and for each shortcut and terminal
case that must retain its existing behavior.

GitOrigin-RevId: 3d8464d805f95f677cce5c46ae00338e611d776a
This commit is contained in:
Benjamin Carlsson authored and copyberry committed 2026-09-03 17:28:48 +00:00
1 parent 1d74c3ba1e
commit 1d6727c0b5
5 files changed
+365 -2

No files matched your search

+10 -1
View File
@@ -837,7 +837,16 @@ impl App {
self.handle_draw_pre_render(tui, screen_size)?;
}
let event = if let TuiEvent::Key(key_event) = event {
let event = if let TuiEvent::Key(mut key_event) = event {
let escape = KeyEvent::new(KeyCode::Esc, KeyModifiers::NONE);
if self.should_recover_vim_insert_escape(key_event) {
// Restore both strokes before chords or global shortcuts can consume them.
if let Some(escape) = self.route_key_chord_event(tui, escape) {
self.handle_key_event(tui, app_server, escape).await;
}
key_event.modifiers.remove(KeyModifiers::ALT);
}
let Some(key_event) = self.route_key_chord_event(tui, key_event) else {
return Ok(AppRunControl::Continue);
};