mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +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
@@ -45,6 +45,37 @@ pub(crate) struct KeyBinding {
|
||||
modifiers: KeyModifiers,
|
||||
}
|
||||
|
||||
/// A user-visible shortcut made from one key or a two-key chord.
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
pub(crate) enum ShortcutHint {
|
||||
Single(KeyBinding),
|
||||
Chord {
|
||||
prefix: KeyBinding,
|
||||
completion: KeyBinding,
|
||||
},
|
||||
}
|
||||
|
||||
impl ShortcutHint {
|
||||
pub(crate) fn display_label(self) -> String {
|
||||
match self {
|
||||
Self::Single(binding) => binding.display_label(),
|
||||
Self::Chord { prefix, completion } => {
|
||||
format!("{} {}", prefix.display_label(), completion.display_label())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn is_press(self, event: KeyEvent) -> bool {
|
||||
matches!(self, Self::Single(binding) if binding.is_press(event))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<KeyBinding> for ShortcutHint {
|
||||
fn from(binding: KeyBinding) -> Self {
|
||||
Self::Single(binding)
|
||||
}
|
||||
}
|
||||
|
||||
impl KeyBinding {
|
||||
pub(crate) const fn new(key: KeyCode, modifiers: KeyModifiers) -> Self {
|
||||
Self { key, modifiers }
|
||||
@@ -193,6 +224,12 @@ impl From<&KeyBinding> for Span<'static> {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ShortcutHint> for Span<'static> {
|
||||
fn from(hint: ShortcutHint) -> Self {
|
||||
Span::styled(hint.display_label(), key_hint_style())
|
||||
}
|
||||
}
|
||||
|
||||
fn key_hint_style() -> Style {
|
||||
Style::default().dim()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user