TUI: Add Ctrl/Cmd+Z Undo for Cleared Drafts
Problem Statement
In the TUI chat composer, pressing Ctrl+C clears the current draft and stores it in history. However, there is no shortcut to immediately restore the most recent cleared draft. Users expect Ctrl+Z (or Cmd+Z on macOS) to act as an “undo clear” action, but this functionality is missing.
Steps to Reproduce
Type any text into the TUI chat composer.
Press Ctrl+C to clear the draft.
Press Ctrl+Z (or Cmd+Z).
Notice that the draft is not restored.
Expected Behavior
When the composer is empty, pressing Ctrl+Z / Cmd+Z should restore the most recent cleared draft from history.
This should behave identically to pressing the Up arrow immediately after clearing.
Root Cause
The function ChatComposer::handle_key_event_without_popup in
codex-rs/tui/src/bottom_pane/chat_composer.rs handles multiple key events but does not include a case for Ctrl+Z.
The history system already supports restoring cleared drafts via Up/Down navigation.
The missing feature is simply the absence of a match arm for KeyCode::Char('z') with CONTROL or SUPER modifiers.
Proposed Solution
Add a new handler in handle_key_event_without_popup:
rust
// Ctrl+Z or Cmd+Z: undo clear (restore most recent draft)
KeyEvent {
code: KeyCode::Char('z'),
modifiers,
kind: KeyEventKind::Press,
..
} if self.is_empty()
&& (modifiers.contains(KeyModifiers::CONTROL)
|| modifiers.contains(KeyModifiers::SUPER))
&& !modifiers.contains(KeyModifiers::ALT) => {
let replace_entry = self.history.navigate_up(&self.app_event_tx);
if let Some(entry) = replace_entry {
self.apply_history_entry(entry);
return (InputResult::None, true);
}
(InputResult::None, false)
}
Why This Works
Cross‑platform consistency: Ctrl on Windows/Linux, Cmd on macOS.
Conditionally active: Only when composer is empty, avoiding conflicts with text editing undo.
Reuses existing logic: Calls navigate_up() and apply_history_entry() exactly like Up arrow navigation.
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗