From 39c6485cb75b4b55d8cefb3c7d468253f89a3376 Mon Sep 17 00:00:00 2001 From: Felipe Coury Date: Tue, 24 Nov 2026 15:31:29 +0000 Subject: [PATCH] Fix Home and End navigation in the agent center (#63677) ## Why The agent center's `Home` and `End` shortcuts skipped the **Show more** row, so pressing `End` could stop before the last selectable row. ## What changed Jump to the first or last selectable row and preserve whether **Show more** is selected across view refreshes. Reconcile selection when toggling search on and let the cancel shortcut dismiss search even when the view cannot return to chat. ## Testing Add a regression test that presses `End`, `Home`, and `End` across view refreshes and verifies that `Enter` on **Show more** requests another page. GitOrigin-RevId: e508c7926ce83b68c229d638364e6e41f671490e --- codex-rs/tui/src/app/agent_center/hints.rs | 14 ++++----- .../tui/src/app/agent_center/navigation.rs | 14 ++++++++- codex-rs/tui/src/app/agent_center/rows.rs | 24 ++++++++------- codex-rs/tui/src/app/agent_center_tests.rs | 29 +++++++++++++++++++ codex-rs/tui/src/app/agents_overview_view.rs | 22 ++++++-------- 5 files changed, 70 insertions(+), 33 deletions(-) diff --git a/codex-rs/tui/src/app/agent_center/hints.rs b/codex-rs/tui/src/app/agent_center/hints.rs index f22fbc059f..8855e68f7a 100644 --- a/codex-rs/tui/src/app/agent_center/hints.rs +++ b/codex-rs/tui/src/app/agent_center/hints.rs @@ -213,15 +213,11 @@ impl AgentsOverviewView { } } if let Some(hint) = self.center_list_hint(ListAction::Accept) { - hints.push(( - hint.display_label(), - if state.rename_target.is_some() { - "rename" - } else { - "open" - } - .into(), - )); + let action = match self.selected { + _ if state.rename_target.is_some() => "rename", + _ => "open", + }; + hints.push((hint.display_label(), action.into())); } if !state.editing_metadata() && let Some(hint) = self diff --git a/codex-rs/tui/src/app/agent_center/navigation.rs b/codex-rs/tui/src/app/agent_center/navigation.rs index 2fdd42a84b..2260942c37 100644 --- a/codex-rs/tui/src/app/agent_center/navigation.rs +++ b/codex-rs/tui/src/app/agent_center/navigation.rs @@ -69,7 +69,7 @@ impl AgentsOverviewView { continue; } if previous.is_none_or(|previous| !self.same_group(state.grouping, previous, index)) { - if previous.is_some() { + if !entries.is_empty() { entries.push(TaskListRow::Gap); } entries.push(TaskListRow::Group(index)); @@ -83,6 +83,18 @@ impl AgentsOverviewView { entries } + pub(in crate::app::agents_overview_view) fn jump_selection(&mut self, action: ListAction) { + let indices = self.selectable_indices(); + let selected = match action { + ListAction::JumpTop => indices.first(), + ListAction::JumpBottom => indices.last(), + _ => return, + } + .copied(); + self.selected = selected.unwrap_or(usize::MAX); + self.state().show_more_selected = selected == Some(usize::MAX); + } + pub(in crate::app::agents_overview_view) fn select_section( &mut self, direction: SectionDirection, diff --git a/codex-rs/tui/src/app/agent_center/rows.rs b/codex-rs/tui/src/app/agent_center/rows.rs index 3d632db138..d78ca5aa93 100644 --- a/codex-rs/tui/src/app/agent_center/rows.rs +++ b/codex-rs/tui/src/app/agent_center/rows.rs @@ -50,13 +50,15 @@ impl AgentsOverviewView { let indices = self.selectable_indices(); let mut state = self.state(); let padding = u16::from(area.height >= 3); - let viewport = row(area, padding, area.height - padding * 2); - state.list_width = viewport.width; + state.list_width = area.width; + let top_padding = padding; + let viewport = row(area, top_padding, area.height - top_padding - padding); state.page_height = usize::from(viewport.height); + let entries = self.center_rows(&indices, &state); if area.is_empty() { return; } - if indices.is_empty() { + if entries.is_empty() { line( if state.connection_notice.is_some() { "Reconnecting…" @@ -96,31 +98,32 @@ impl AgentsOverviewView { }; (label, dot) }; - let entries = self.center_rows(&indices, &state); let reference = chrono::Utc::now(); let sort = if state.searching { state.search_sort } else { HistorySort::Updated }; - let age = |task: &AgentsOverviewRow| { + let age = |timestamp| { format_relative_time( reference, - chrono::DateTime::from_timestamp(sort.timestamp(&task.thread), /*nsecs*/ 0), + chrono::DateTime::from_timestamp(timestamp, /*nsecs*/ 0), ) }; + let task_age = |task: &AgentsOverviewRow| age(sort.timestamp(&task.thread)); let widths = (state.list_width >= STATUS_COLUMNS_MIN_WIDTH).then(|| { let mut status_width = "Status".width(); let mut updated_width = sort.label().width(); for task in indices.iter().filter_map(|&index| self.rows.get(index)) { status_width = status_width.max(status_for(task).0.width()); - updated_width = updated_width.max(age(task).width()); + updated_width = updated_width.max(task_age(task).width()); } (status_width.min(11) as u16, updated_width.min(9) as u16) }); if padding > 0 && self.dock_focused.is_none() { let (title, status, updated) = columns(row(area, /*offset*/ 0, /*height*/ 1), widths); - line("Tasks".dim(), title, buf); + let heading = "Tasks"; + line(heading.dim(), title, buf); line("Status".dim(), status, buf); Line::from(sort.label().dim()) .right_aligned() @@ -213,7 +216,8 @@ impl AgentsOverviewView { let count = indices .iter() .filter(|&&candidate| { - candidate != usize::MAX && self.same_group(state.grouping, candidate, index) + candidate < self.rows.len() + && self.same_group(state.grouping, candidate, index) }) .count(); let total = (0..self.rows.len()) @@ -313,7 +317,7 @@ impl AgentsOverviewView { line(task_title, title, buf); line(Line::from(status).style(style), status_area, buf); if !updated.is_empty() { - Line::from(age(task)) + Line::from(task_age(task)) .style(if index == self.selected { style } else { diff --git a/codex-rs/tui/src/app/agent_center_tests.rs b/codex-rs/tui/src/app/agent_center_tests.rs index e7512e34ec..d96219c33a 100644 --- a/codex-rs/tui/src/app/agent_center_tests.rs +++ b/codex-rs/tui/src/app/agent_center_tests.rs @@ -30,6 +30,35 @@ pub(super) fn screen(view: &AgentsOverviewView, width: u16, height: u16) -> Stri ) } +#[tokio::test] +async fn live_center_home_and_end_preserve_selection_across_refreshes() { + let mut app = make_test_app().await; + let (tx, mut events) = tokio::sync::mpsc::unbounded_channel(); + app.app_event_tx = AppEventSender::new(tx); + let thread = overview_thread( + ThreadId::from_u128(/*value*/ 42), + /*parent_thread_id*/ None, + "Task", + ThreadStatus::Idle, + ); + let state = &app.agents_overview.view_state; + state.lock().unwrap().has_more = true; + let view = || app.agents_overview_view(vec![thread.clone()], /*selected_thread_id*/ None); + let mut center = view(); + center.handle_key_event(KeyCode::End.into()); + assert!(screen(&view(), /*width*/ 88, /*height*/ 14).contains("› Show more")); + let mut center = view(); + center.handle_key_event(KeyCode::Home.into()); + assert!(!screen(&view(), /*width*/ 88, /*height*/ 14).contains("› Show more")); + let mut center = view(); + center.handle_key_event(KeyCode::End.into()); + view().handle_key_event(KeyCode::Enter.into()); + assert!( + std::iter::from_fn(|| events.try_recv().ok()) + .any(|event| matches!(event, AppEvent::ShowMoreAgentsOverview)) + ); +} + #[tokio::test] async fn live_center_keeps_status_order_across_progress_refreshes() { let mut app = make_test_app_with_chat().await; diff --git a/codex-rs/tui/src/app/agents_overview_view.rs b/codex-rs/tui/src/app/agents_overview_view.rs index 78506e01f0..0bd762a3d5 100644 --- a/codex-rs/tui/src/app/agents_overview_view.rs +++ b/codex-rs/tui/src/app/agents_overview_view.rs @@ -484,6 +484,7 @@ impl AgentsOverviewView { self.load_search_matches(/*additional*/ 10); return; } + if self.selected == usize::MAX && self.state().has_more { if !self.state().loading { self.state().loading = true; @@ -798,11 +799,14 @@ impl BottomPaneView for AgentsOverviewView { if state.searching { drop(state); self.on_ctrl_c(); + return; } else { state.browse_selection = self.rows.get(self.selected).map(|row| row.thread_id); state.searching = true; } } + drop(state); + self.reconcile_command_center_selection(); return; } @@ -817,11 +821,8 @@ impl BottomPaneView for AgentsOverviewView { Some(action @ (ListAction::PageUp | ListAction::PageDown)) => { self.page_selection(action) } - Some(ListAction::JumpTop) => { - self.selected = self.visible_indices().first().copied().unwrap_or(0); - } - Some(ListAction::JumpBottom) => { - self.selected = self.visible_indices().last().copied().unwrap_or(0); + Some(action @ (ListAction::JumpTop | ListAction::JumpBottom)) => { + self.jump_selection(action) } _ => {} } @@ -943,16 +944,11 @@ impl BottomPaneView for AgentsOverviewView { match action { ListAction::MoveUp => self.move_selection(/*forward*/ false), ListAction::MoveDown => self.move_selection(/*forward*/ true), - ListAction::JumpTop => { - self.selected = self.visible_indices().first().copied().unwrap_or(0); - } - ListAction::JumpBottom => { - self.selected = self.visible_indices().last().copied().unwrap_or(0); - } + ListAction::JumpTop | ListAction::JumpBottom => self.jump_selection(action), ListAction::Accept => self.activate(), ListAction::Cancel => { - if self.can_return_to_chat - && matches!(self.on_ctrl_c(), CancellationEvent::NotHandled) + if matches!(self.on_ctrl_c(), CancellationEvent::NotHandled) + && self.can_return_to_chat { self.state().completion = Some(ViewCompletion::Cancelled); }