mirror of
https://github.com/openai/codex.git
synced 2026-11-28 07:32:19 +00:00
Support two-stroke TUI key chords (#36511)
## What changed - Accept two-stroke bindings such as `ctrl-x ctrl-s` in TUI keymap configuration while preserving arrays as alternative bindings. - Route chords through the active TUI context, show pending and configured chord hints, and cancel pending chords on `esc`, context changes, or a one-second timeout. - Extend `/keymap` to capture, add, replace, and display key chords. - Reject chords that conflict with active single-key bindings, overlapping-context chords, or reserved terminal shortcuts. ## Testing - Add coverage for chord parsing, validation, matching, timeout and cancellation behavior, context dispatch, key capture, and rendered shortcut hints. GitOrigin-RevId: dfdede03f518d4936ad8621ebf5537026f2b282e
This commit is contained in:
1 parent
a1dd74b535
commit
1e85ca099e
61 files changed
+3503
-660
No files matched your search
@@ -43,6 +43,7 @@
|
||||
//! `FooterProps` mapping.
|
||||
use crate::key_hint;
|
||||
use crate::key_hint::KeyBinding;
|
||||
use crate::key_hint::ShortcutHint;
|
||||
use crate::render::line_utils::prefix_lines;
|
||||
use crate::status::format_tokens_compact;
|
||||
use crate::ui_consts::FOOTER_INDENT_COLS;
|
||||
@@ -106,30 +107,30 @@ const FOOTER_CONTEXT_GAP_COLS: u16 = 1;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub(crate) struct FooterKeyHints {
|
||||
pub(crate) toggle_shortcuts: Option<KeyBinding>,
|
||||
pub(crate) queue: Option<KeyBinding>,
|
||||
pub(crate) insert_newline: Option<KeyBinding>,
|
||||
pub(crate) external_editor: Option<KeyBinding>,
|
||||
pub(crate) edit_previous: Option<KeyBinding>,
|
||||
pub(crate) show_transcript: Option<KeyBinding>,
|
||||
pub(crate) history_search: Option<KeyBinding>,
|
||||
pub(crate) reasoning_down: Option<KeyBinding>,
|
||||
pub(crate) reasoning_up: Option<KeyBinding>,
|
||||
pub(crate) toggle_shortcuts: Option<ShortcutHint>,
|
||||
pub(crate) queue: Option<ShortcutHint>,
|
||||
pub(crate) insert_newline: Option<ShortcutHint>,
|
||||
pub(crate) external_editor: Option<ShortcutHint>,
|
||||
pub(crate) edit_previous: Option<ShortcutHint>,
|
||||
pub(crate) show_transcript: Option<ShortcutHint>,
|
||||
pub(crate) history_search: Option<ShortcutHint>,
|
||||
pub(crate) reasoning_down: Option<ShortcutHint>,
|
||||
pub(crate) reasoning_up: Option<ShortcutHint>,
|
||||
}
|
||||
|
||||
impl FooterKeyHints {
|
||||
#[cfg(test)]
|
||||
pub(crate) fn default_bindings() -> Self {
|
||||
Self {
|
||||
toggle_shortcuts: Some(key_hint::plain(KeyCode::Char('?'))),
|
||||
queue: Some(key_hint::plain(KeyCode::Tab)),
|
||||
insert_newline: Some(key_hint::ctrl(KeyCode::Char('j'))),
|
||||
external_editor: Some(key_hint::ctrl(KeyCode::Char('g'))),
|
||||
edit_previous: Some(key_hint::plain(KeyCode::Esc)),
|
||||
show_transcript: Some(key_hint::ctrl(KeyCode::Char('t'))),
|
||||
history_search: Some(key_hint::ctrl(KeyCode::Char('r'))),
|
||||
reasoning_down: Some(key_hint::alt(KeyCode::Char(','))),
|
||||
reasoning_up: Some(key_hint::alt(KeyCode::Char('.'))),
|
||||
toggle_shortcuts: Some(key_hint::plain(KeyCode::Char('?')).into()),
|
||||
queue: Some(key_hint::plain(KeyCode::Tab).into()),
|
||||
insert_newline: Some(key_hint::ctrl(KeyCode::Char('j')).into()),
|
||||
external_editor: Some(key_hint::ctrl(KeyCode::Char('g')).into()),
|
||||
edit_previous: Some(key_hint::plain(KeyCode::Esc).into()),
|
||||
show_transcript: Some(key_hint::ctrl(KeyCode::Char('t')).into()),
|
||||
history_search: Some(key_hint::ctrl(KeyCode::Char('r')).into()),
|
||||
reasoning_down: Some(key_hint::alt(KeyCode::Char(',')).into()),
|
||||
reasoning_up: Some(key_hint::alt(KeyCode::Char('.')).into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1087,7 +1088,9 @@ impl ShortcutDescriptor {
|
||||
| ShortcutId::FilePaths
|
||||
| ShortcutId::PasteImage
|
||||
| ShortcutId::Quit
|
||||
| ShortcutId::ChangeMode => self.binding_for(state).map(|binding| binding.key),
|
||||
| ShortcutId::ChangeMode => self
|
||||
.binding_for(state)
|
||||
.map(|binding| ShortcutHint::Single(binding.key)),
|
||||
}?;
|
||||
let mut line = Line::from(vec![self.prefix.into(), key.into()]);
|
||||
match self.id {
|
||||
@@ -1576,7 +1579,7 @@ mod tests {
|
||||
status_line_value: None,
|
||||
status_line_enabled: false,
|
||||
key_hints: FooterKeyHints {
|
||||
insert_newline: Some(key_hint::shift(KeyCode::Enter)),
|
||||
insert_newline: Some(key_hint::shift(KeyCode::Enter).into()),
|
||||
..FooterKeyHints::default_bindings()
|
||||
},
|
||||
active_agent_label: None,
|
||||
|
||||
Reference in new issue
Block a user