mirror of
https://github.com/openai/codex.git
synced 2026-11-28 07:32:19 +00:00
feat(tui): standardize picker navigation keys (#22347)
## Why Picker-style UI in the TUI has accumulated a mix of hardcoded navigation keys. Some lists supported page movement, some did not; some accepted Vim-like keys, while others only accepted arrows; and tabbed or horizontally adjustable pickers had no shared keymap action for left/right movement. This PR makes picker/list navigation consistent and configurable so users can rely on the same defaults across the TUI. ## What Changed - Adds shared list keymap actions for: - vertical movement: `move_up`, `move_down` - horizontal movement: `move_left`, `move_right` - paging and jumps: `page_up`, `page_down`, `jump_top`, `jump_bottom` - Adds defaults: - Up/down: arrows, `Ctrl+P/N`, `Ctrl+K/J`, and plain `k/j` where text input is not active - Page up/down: `PageUp/PageDown` and `Ctrl+B/F` - First/last: `Home/End` - Left/right: `Left/Right` and `Ctrl+H/L` - Wires the shared list keymap through picker and list surfaces including session resume, multi-select, tabbed selection lists, settings-style lists, app-link selection, MCP elicitation, request-user-input, and the OSS selection wizard. - Keeps search behavior intact by reserving printable characters for query text in searchable pickers. - Updates keymap setup actions, config schema, snapshots, and focused coverage for the new list actions. ## How to Test 1. Start Codex from this branch and open the session picker, for example with an existing session history. 2. In the session list, verify that `Ctrl+J/K` moves the selection down/up. 3. Verify that `Ctrl+F/B` pages down/up and `Home/End` jumps to the first/last visible session. 4. Type printable search text such as `j` or `k` and confirm it updates the query instead of navigating. 5. Focus a picker control that changes values horizontally, such as a session picker toolbar control, and verify `Ctrl+H/L` changes the focused value like left/right arrows. Targeted tests run: - `cargo test -p codex-tui keymap::tests::` - `cargo test -p codex-tui keymap_setup::tests::` - `cargo test -p codex-tui horizontal_list_keys` - `cargo test -p codex-tui page_and_jump_navigation_use_list_keymap` - `cargo test -p codex-tui ctrl_h_l_move_provider_selection` - `cargo test -p codex-tui scroll_state::tests` - `cargo test -p codex-tui switching_tabs_changes_visible_items_and_clears_search` - `cargo test -p codex-tui toggle_sort_key_reloads_with_new_sort` Also ran `just write-config-schema`, `just fmt`, `just fix -p codex-tui`, `just argument-comment-lint`, and `git diff --check`. Note: `cargo test -p codex-tui` was attempted and still aborts in the pre-existing `tests::fork_last_filters_latest_session_by_cwd_unless_show_all` stack overflow, which is unrelated to this branch.
This commit is contained in:
1 parent
441c2f818f
commit
3d517fbd00
37 files changed
+1635
-426
No files matched your search
@@ -14,6 +14,10 @@ use ratatui::widgets::Widget;
|
||||
use crate::app_event::AppEvent;
|
||||
use crate::app_event_sender::AppEventSender;
|
||||
use crate::key_hint;
|
||||
use crate::key_hint::KeyBindingListExt;
|
||||
use crate::key_hint::is_plain_text_key_event;
|
||||
use crate::keymap::ListKeymap;
|
||||
use crate::keymap::primary_binding;
|
||||
use crate::render::Insets;
|
||||
use crate::render::RectExt as _;
|
||||
use crate::render::renderable::ColumnRenderable;
|
||||
@@ -49,10 +53,15 @@ pub(crate) struct SkillsToggleView {
|
||||
footer_hint: Line<'static>,
|
||||
search_query: String,
|
||||
filtered_indices: Vec<usize>,
|
||||
keymap: ListKeymap,
|
||||
}
|
||||
|
||||
impl SkillsToggleView {
|
||||
pub(crate) fn new(items: Vec<SkillsToggleItem>, app_event_tx: AppEventSender) -> Self {
|
||||
pub(crate) fn new(
|
||||
items: Vec<SkillsToggleItem>,
|
||||
app_event_tx: AppEventSender,
|
||||
keymap: ListKeymap,
|
||||
) -> Self {
|
||||
let mut header = ColumnRenderable::new();
|
||||
header.push(Line::from("Enable/Disable Skills".bold()));
|
||||
header.push(Line::from(
|
||||
@@ -65,9 +74,10 @@ impl SkillsToggleView {
|
||||
complete: false,
|
||||
app_event_tx,
|
||||
header: Box::new(header),
|
||||
footer_hint: skills_toggle_hint_line(),
|
||||
footer_hint: skills_toggle_hint_line(&keymap),
|
||||
search_query: String::new(),
|
||||
filtered_indices: Vec::new(),
|
||||
keymap,
|
||||
};
|
||||
view.apply_filter();
|
||||
view
|
||||
@@ -161,6 +171,30 @@ impl SkillsToggleView {
|
||||
self.state.ensure_visible(len, visible);
|
||||
}
|
||||
|
||||
fn page_up(&mut self) {
|
||||
let len = self.visible_len();
|
||||
let visible = Self::max_visible_rows(len);
|
||||
self.state.page_up_clamped(len, visible);
|
||||
}
|
||||
|
||||
fn page_down(&mut self) {
|
||||
let len = self.visible_len();
|
||||
let visible = Self::max_visible_rows(len);
|
||||
self.state.page_down_clamped(len, visible);
|
||||
}
|
||||
|
||||
fn jump_top(&mut self) {
|
||||
let len = self.visible_len();
|
||||
let visible = Self::max_visible_rows(len);
|
||||
self.state.jump_top(len, visible);
|
||||
}
|
||||
|
||||
fn jump_bottom(&mut self) {
|
||||
let len = self.visible_len();
|
||||
let visible = Self::max_visible_rows(len);
|
||||
self.state.jump_bottom(len, visible);
|
||||
}
|
||||
|
||||
fn toggle_selected(&mut self) {
|
||||
let Some(idx) = self.state.selected_idx else {
|
||||
return;
|
||||
@@ -200,34 +234,29 @@ impl SkillsToggleView {
|
||||
|
||||
impl BottomPaneView for SkillsToggleView {
|
||||
fn handle_key_event(&mut self, key_event: KeyEvent) {
|
||||
// Printable characters always feed search. Movement aliases such as
|
||||
// plain j/k only apply through non-text events or modified bindings.
|
||||
let allow_plain_char_navigation = !is_plain_text_key_event(key_event);
|
||||
|
||||
match key_event {
|
||||
KeyEvent {
|
||||
code: KeyCode::Up, ..
|
||||
_ if allow_plain_char_navigation && self.keymap.move_up.is_pressed(key_event) => {
|
||||
self.move_up()
|
||||
}
|
||||
| KeyEvent {
|
||||
code: KeyCode::Char('p'),
|
||||
modifiers: KeyModifiers::CONTROL,
|
||||
..
|
||||
_ if allow_plain_char_navigation && self.keymap.move_down.is_pressed(key_event) => {
|
||||
self.move_down()
|
||||
}
|
||||
| KeyEvent {
|
||||
code: KeyCode::Char('\u{0010}'),
|
||||
modifiers: KeyModifiers::NONE,
|
||||
..
|
||||
} /* ^P */ => self.move_up(),
|
||||
KeyEvent {
|
||||
code: KeyCode::Down,
|
||||
..
|
||||
_ if allow_plain_char_navigation && self.keymap.page_up.is_pressed(key_event) => {
|
||||
self.page_up()
|
||||
}
|
||||
| KeyEvent {
|
||||
code: KeyCode::Char('n'),
|
||||
modifiers: KeyModifiers::CONTROL,
|
||||
..
|
||||
_ if allow_plain_char_navigation && self.keymap.page_down.is_pressed(key_event) => {
|
||||
self.page_down()
|
||||
}
|
||||
_ if allow_plain_char_navigation && self.keymap.jump_top.is_pressed(key_event) => {
|
||||
self.jump_top()
|
||||
}
|
||||
_ if allow_plain_char_navigation && self.keymap.jump_bottom.is_pressed(key_event) => {
|
||||
self.jump_bottom()
|
||||
}
|
||||
| KeyEvent {
|
||||
code: KeyCode::Char('\u{000e}'),
|
||||
modifiers: KeyModifiers::NONE,
|
||||
..
|
||||
} /* ^N */ => self.move_down(),
|
||||
KeyEvent {
|
||||
code: KeyCode::Backspace,
|
||||
..
|
||||
@@ -239,15 +268,9 @@ impl BottomPaneView for SkillsToggleView {
|
||||
code: KeyCode::Char(' '),
|
||||
modifiers: KeyModifiers::NONE,
|
||||
..
|
||||
}
|
||||
| KeyEvent {
|
||||
code: KeyCode::Enter,
|
||||
modifiers: KeyModifiers::NONE,
|
||||
..
|
||||
} => self.toggle_selected(),
|
||||
KeyEvent {
|
||||
code: KeyCode::Esc, ..
|
||||
} => {
|
||||
_ if self.keymap.accept.is_pressed(key_event) => self.toggle_selected(),
|
||||
_ if self.keymap.cancel.is_pressed(key_event) => {
|
||||
self.on_ctrl_c();
|
||||
}
|
||||
KeyEvent {
|
||||
@@ -364,16 +387,37 @@ impl Renderable for SkillsToggleView {
|
||||
}
|
||||
}
|
||||
|
||||
fn skills_toggle_hint_line() -> Line<'static> {
|
||||
Line::from(vec![
|
||||
"Press ".into(),
|
||||
key_hint::plain(KeyCode::Char(' ')).into(),
|
||||
" or ".into(),
|
||||
key_hint::plain(KeyCode::Enter).into(),
|
||||
" to toggle; ".into(),
|
||||
key_hint::plain(KeyCode::Esc).into(),
|
||||
" to close".into(),
|
||||
])
|
||||
fn skills_toggle_hint_line(keymap: &ListKeymap) -> Line<'static> {
|
||||
let space = key_hint::plain(KeyCode::Char(' '));
|
||||
let accept = primary_binding(&keymap.accept).filter(|binding| *binding != space);
|
||||
let cancel = primary_binding(&keymap.cancel);
|
||||
|
||||
match (accept, cancel) {
|
||||
(Some(accept), Some(cancel)) => Line::from(vec![
|
||||
"Press ".into(),
|
||||
space.into(),
|
||||
" or ".into(),
|
||||
accept.into(),
|
||||
" to toggle; ".into(),
|
||||
cancel.into(),
|
||||
" to close".into(),
|
||||
]),
|
||||
(Some(accept), None) => Line::from(vec![
|
||||
"Press ".into(),
|
||||
space.into(),
|
||||
" or ".into(),
|
||||
accept.into(),
|
||||
" to toggle".into(),
|
||||
]),
|
||||
(None, Some(cancel)) => Line::from(vec![
|
||||
"Press ".into(),
|
||||
space.into(),
|
||||
" to toggle; ".into(),
|
||||
cancel.into(),
|
||||
" to close".into(),
|
||||
]),
|
||||
(None, None) => Line::from(vec!["Press ".into(), space.into(), " to toggle".into()]),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -429,7 +473,23 @@ mod tests {
|
||||
path: test_path_buf("/tmp/skills/changelog_writer.toml").abs(),
|
||||
},
|
||||
];
|
||||
let view = SkillsToggleView::new(items, tx);
|
||||
let view = SkillsToggleView::new(items, tx, crate::keymap::RuntimeKeymap::defaults().list);
|
||||
assert_snapshot!("skills_toggle_basic", render_lines(&view, /*width*/ 72));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn footer_hint_uses_list_keymap_accept_and_cancel() {
|
||||
let (tx_raw, _rx) = unbounded_channel::<AppEvent>();
|
||||
let tx = AppEventSender::new(tx_raw);
|
||||
let mut keymap = crate::keymap::RuntimeKeymap::defaults().list;
|
||||
keymap.accept = vec![key_hint::ctrl(KeyCode::Char('t'))];
|
||||
keymap.cancel = vec![key_hint::ctrl(KeyCode::Char('x'))];
|
||||
let view = SkillsToggleView::new(Vec::new(), tx, keymap);
|
||||
let rendered = render_lines(&view, /*width*/ 72);
|
||||
|
||||
assert!(rendered.contains("ctrl + t"));
|
||||
assert!(rendered.contains("ctrl + x"));
|
||||
assert!(!rendered.contains("enter"));
|
||||
assert!(!rendered.contains("esc"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user