Files
codex/codex-rs/tui/src/app/agents_overview_selection.rs
T
Benjamin Carlsson 47379efd52 Keep Command Center selection adjacent after task removal (#50505)
## Why

Archiving or deleting the selected task could make Command Center selection jump to the current task instead of a neighboring task in the displayed list.

## What changed

Choose the next surviving task in displayed order before removing tasks, falling back to the previous task when needed. Apply this selection behavior to archive, delete, and hide actions, respecting filtering and grouping.

Preserve the pending selection across view rebuilds, batched removals, and duplicate server notifications. Allow selection to fall back when a rename target disappears while retaining the existing notice about its unsubmitted title.

## Testing

Add regression tests and snapshots for archive/delete selection across project, status, and model grouping, with and without filtering. Cover removal of the attached task, external removal notifications, removal of a pending successor, repeated repaints, and an empty task list. Update the disappeared-rename-target snapshot to verify that the remaining selection is preserved.

GitOrigin-RevId: ca93d664fadbc602993fbdae316c7a375b449345
2026-10-03 03:06:40 +00:00

33 lines
1.2 KiB
Rust

//! Preserves Command Center selection across local and server-driven removals.
//! Choose against the displayed order before mutation; pending successors survive
//! batched removals and duplicate completion notifications until the next repaint.
use super::AGENTS_OVERVIEW_VIEW_ID;
use super::App;
use codex_protocol::ThreadId;
use std::collections::HashSet;
impl App {
pub(in crate::app) fn prepare_agents_overview_removal(&mut self, removed: &HashSet<ThreadId>) {
let selected = self.agents_overview.selection_after_removal.or_else(|| {
let index = self
.chat_widget
.selected_index_for_present_view(AGENTS_OVERVIEW_VIEW_ID)?;
self.agents_overview.visible_thread_ids.get(index).copied()
});
let Some(selected) = selected.filter(|id| removed.contains(id)) else {
return;
};
let threads = self
.agents_overview
.threads
.values()
.flatten()
.cloned()
.collect();
self.agents_overview.selection_after_removal = self
.agents_overview_view(threads, Some(selected))
.selection_after_removal(removed);
}
}