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:
Felipe Coury authored and GitHub committed 2026-05-13 15:33:27 +00:00
1 parent 441c2f818f
commit 3d517fbd00
37 files changed
+1635 -426

No files matched your search

+87 -18
View File
@@ -29,6 +29,8 @@ use crate::app::app_server_requests::ResolvedAppServerRequest;
use crate::app_event::AppEvent;
use crate::app_event_sender::AppEventSender;
use crate::key_hint;
use crate::key_hint::KeyBindingListExt;
use crate::keymap::ListKeymap;
use crate::render::Insets;
use crate::render::RectExt as _;
use crate::style::user_message_style;
@@ -238,10 +240,24 @@ pub(crate) struct AppLinkView {
screen: AppLinkScreen,
selected_action: usize,
complete: bool,
list_keymap: ListKeymap,
}
impl AppLinkView {
#[cfg(test)]
pub(crate) fn new(params: AppLinkViewParams, app_event_tx: AppEventSender) -> Self {
Self::new_with_keymap(
params,
app_event_tx,
crate::keymap::RuntimeKeymap::defaults().list,
)
}
pub(crate) fn new_with_keymap(
params: AppLinkViewParams,
app_event_tx: AppEventSender,
list_keymap: ListKeymap,
) -> Self {
let AppLinkViewParams {
app_id,
title,
@@ -269,6 +285,7 @@ impl AppLinkView {
screen: AppLinkScreen::Link,
selected_action: 0,
complete: false,
list_keymap,
}
}
@@ -679,10 +696,6 @@ impl BottomPaneView for AppLinkView {
KeyEvent {
code: KeyCode::Up, ..
}
| KeyEvent {
code: KeyCode::Left,
..
}
| KeyEvent {
code: KeyCode::BackTab,
..
@@ -691,20 +704,12 @@ impl BottomPaneView for AppLinkView {
code: KeyCode::Char('k'),
modifiers: KeyModifiers::NONE,
..
}
| KeyEvent {
code: KeyCode::Char('h'),
modifiers: KeyModifiers::NONE,
..
} => self.move_selection_prev(),
_ if self.list_keymap.move_left.is_pressed(key_event) => self.move_selection_prev(),
KeyEvent {
code: KeyCode::Down,
..
}
| KeyEvent {
code: KeyCode::Right,
..
}
| KeyEvent {
code: KeyCode::Tab, ..
}
@@ -712,12 +717,8 @@ impl BottomPaneView for AppLinkView {
code: KeyCode::Char('j'),
modifiers: KeyModifiers::NONE,
..
}
| KeyEvent {
code: KeyCode::Char('l'),
modifiers: KeyModifiers::NONE,
..
} => self.move_selection_next(),
_ if self.list_keymap.move_right.is_pressed(key_event) => self.move_selection_next(),
KeyEvent {
code: KeyCode::Char(c),
modifiers: KeyModifiers::NONE,
@@ -1087,6 +1088,74 @@ mod tests {
assert!(view.terminal_title_requires_action());
}
#[test]
fn horizontal_list_keys_move_action_selection() {
let (tx_raw, _rx) = unbounded_channel::<AppEvent>();
let tx = AppEventSender::new(tx_raw);
let mut view = AppLinkView::new(
AppLinkViewParams {
app_id: "connector_1".to_string(),
title: "Notion".to_string(),
description: None,
instructions: "Manage app".to_string(),
url: "https://example.test/notion".to_string(),
is_installed: true,
is_enabled: true,
suggest_reason: None,
suggestion_type: None,
elicitation_target: None,
},
tx,
);
assert_eq!(view.selected_action, 0);
view.handle_key_event(KeyEvent::new(KeyCode::Char('l'), KeyModifiers::CONTROL));
assert_eq!(view.selected_action, 1);
view.handle_key_event(KeyEvent::new(KeyCode::Char('h'), KeyModifiers::CONTROL));
assert_eq!(view.selected_action, 0);
}
#[test]
fn remapped_horizontal_list_keys_control_action_selection() {
let (tx_raw, _rx) = unbounded_channel::<AppEvent>();
let tx = AppEventSender::new(tx_raw);
let mut list_keymap = crate::keymap::RuntimeKeymap::defaults().list;
list_keymap.move_left = vec![key_hint::plain(KeyCode::Char('x'))];
list_keymap.move_right = vec![key_hint::plain(KeyCode::Char('z'))];
let mut view = AppLinkView::new_with_keymap(
AppLinkViewParams {
app_id: "connector_1".to_string(),
title: "Notion".to_string(),
description: None,
instructions: "Manage app".to_string(),
url: "https://example.test/notion".to_string(),
is_installed: true,
is_enabled: true,
suggest_reason: None,
suggestion_type: None,
elicitation_target: None,
},
tx,
list_keymap,
);
assert_eq!(view.selected_action, 0);
view.handle_key_event(KeyEvent::new(KeyCode::Char('l'), KeyModifiers::NONE));
assert_eq!(view.selected_action, 0);
view.handle_key_event(KeyEvent::new(KeyCode::Right, KeyModifiers::NONE));
assert_eq!(view.selected_action, 0);
view.handle_key_event(KeyEvent::new(KeyCode::Char('z'), KeyModifiers::NONE));
assert_eq!(view.selected_action, 1);
view.handle_key_event(KeyEvent::new(KeyCode::Char('h'), KeyModifiers::NONE));
assert_eq!(view.selected_action, 1);
view.handle_key_event(KeyEvent::new(KeyCode::Left, KeyModifiers::NONE));
assert_eq!(view.selected_action, 1);
view.handle_key_event(KeyEvent::new(KeyCode::Char('x'), KeyModifiers::NONE));
assert_eq!(view.selected_action, 0);
}
#[test]
fn toggle_action_sends_set_app_enabled_and_updates_label() {
let (tx_raw, mut rx) = unbounded_channel::<AppEvent>();