Allow Left to open the command center from read-only conversations (#48132)

## What changed

- Let `Left` return to the command center from a conversation open in another app, including while disconnected, without discarding the retained draft.
- Respect editor and Vim keymaps, conflicting shortcuts, and chord prefixes before enabling this navigation.
- Show `←/esc` in the command center hint when `Left` is available; otherwise keep `esc`.

## Testing

Add regression coverage for connected and disconnected navigation, draft preservation, and remapped `Left` with Vim enabled or disabled. Extend attach-conflict coverage to verify that both `Left` and `Esc` preserve the command center selection, and update footer snapshots.

GitOrigin-RevId: 80ef004b548176443ebee03c2a143e723e54c44a
This commit is contained in:
Eric Traut
2026-09-25 16:20:53 +00:00
committed by copyberry
parent 0b430baeb4
commit d9275a63ed
12 changed files with 160 additions and 22 deletions
+3 -1
View File
@@ -1025,7 +1025,9 @@ impl App {
if self.overlay.is_none()
&& self.chat_widget.no_modal_or_popup_active()
&& self.chat_widget.is_external_writer_view()
&& crate::key_hint::plain(KeyCode::Esc).is_press(*key)
&& (crate::key_hint::plain(KeyCode::Esc).is_press(*key)
|| (crate::key_hint::plain(KeyCode::Left).is_press(*key)
&& self.chat_widget.agents_navigation_key_available()))
{
self.open_agents_overview(app_server);
} else if self.reconnect.presentation == reconnect::ReconnectPresentation::Overview {
+15 -15
View File
@@ -2439,22 +2439,22 @@ async fn command_center_attach_conflict_opens_read_only_and_retries() -> Result<
insta::assert_snapshot!("agents_overview_attach_conflict", render_bottom_popup(&app.chat_widget, /*width*/ 96));
});
app.handle_key_event(&mut tui, &mut server, KeyCode::Esc.into())
.await;
for key in [KeyCode::Left, KeyCode::Esc] {
Box::pin(app.handle_tui_event(&mut tui, &mut server, TuiEvent::Key(key.into()))).await?;
assert_eq!(
app.chat_widget
.selected_index_for_present_view(AGENTS_OVERVIEW_VIEW_ID),
selection
);
assert_eq!(
app.chat_widget
.selected_index_for_present_view(AGENTS_OVERVIEW_VIEW_ID),
selection
);
// Opening the displayed task returns to the same frozen snapshot without retrying.
Box::pin(app.handle_event(
&mut tui,
&mut server,
AppEvent::SelectAgentsOverviewThread { thread_id },
))
.await?;
// Opening the displayed task returns to the same frozen snapshot without retrying.
Box::pin(app.handle_event(
&mut tui,
&mut server,
AppEvent::SelectAgentsOverviewThread { thread_id },
))
.await?;
}
assert!(app.chat_widget.no_modal_or_popup_active());
assert!(app.chat_widget.is_external_writer_view());
app.chat_widget.handle_paste(" should be ignored".into());
+8
View File
@@ -562,6 +562,14 @@ impl App {
&& self.overlay.is_none()
&& self.chat_widget.no_modal_or_popup_active()
{
if key_event.kind == KeyEventKind::Press
&& key_event.code == KeyCode::Left
&& key_event.modifiers == KeyModifiers::NONE
&& self.chat_widget.agents_navigation_key_available()
&& !matches!(self.app_server_target, AppServerTarget::Embedded)
{
self.open_agents_overview(app_server);
}
return;
}
@@ -110,6 +110,84 @@ async fn external_writer_view_preserves_draft_from_keys_and_paste() -> Result<()
Ok(())
}
#[tokio::test]
async fn external_writer_view_opens_agents_with_left() -> Result<()> {
for offline in [false, true] {
let (mut app, _, _) = make_test_app_with_channels().await;
app.app_server_target = AppServerTarget::Remote {
endpoint: crate::resolve_remote_addr("ws://127.0.0.1:4500")?,
};
app.chat_widget.insert_str("Retained draft");
app.chat_widget.show_external_writer_thread();
app.reconnect.offline = offline;
let mut app_server = crate::start_embedded_app_server_for_picker(&app.config).await?;
let mut tui = crate::tui::test_support::make_test_tui()?;
tui.set_owned_screen(/*owned*/ true)?;
app.handle_tui_event(
&mut tui,
&mut app_server,
TuiEvent::Key(KeyCode::Left.into()),
)
.await?;
assert!(
app.chat_widget
.selected_index_for_present_view(AGENTS_OVERVIEW_VIEW_ID)
.is_some()
);
assert_eq!(
app.chat_widget.composer_text_with_pending(),
"Retained draft"
);
tui.set_owned_screen(/*owned*/ false)?;
app_server.shutdown().await?;
}
Ok(())
}
#[tokio::test]
async fn external_writer_view_respects_remapped_left() -> Result<()> {
let config: codex_config::types::TuiKeymap = toml::from_str(
"[global]\nopen_transcript = 'left'\n[editor]\nmove_left = 'ctrl-b'\n[list]\nmove_left = 'ctrl-h'\n",
)?;
let keymap = RuntimeKeymap::from_config(&config).map_err(|err| color_eyre::eyre::eyre!(err))?;
for (offline, vim) in [(false, false), (true, false), (false, true), (true, true)] {
let (mut app, _, _) = make_test_app_with_channels().await;
app.app_server_target = AppServerTarget::Remote {
endpoint: crate::resolve_remote_addr("ws://127.0.0.1:4500")?,
};
app.chat_widget.remote_connection =
crate::status::remote_connection::remote_connection_status_value(
&app.app_server_target,
/*server_version*/ None,
);
app.chat_widget.apply_keymap_update(config.clone(), &keymap);
app.keymap = keymap.clone();
if vim {
app.chat_widget.toggle_vim_mode_and_notify();
}
app.chat_widget.show_external_writer_thread();
app.reconnect.offline = offline;
let mut app_server = crate::start_embedded_app_server_for_picker(&app.config).await?;
let mut tui = crate::tui::test_support::make_test_tui()?;
if !offline && vim {
insta::assert_snapshot!(render_bottom_popup(&app.chat_widget, /*width*/ 96));
}
app.handle_tui_event(
&mut tui,
&mut app_server,
TuiEvent::Key(KeyCode::Left.into()),
)
.await?;
assert!(app.chat_widget.no_modal_or_popup_active());
assert_eq!(app.overlay.is_some(), !offline);
app_server.shutdown().await?;
}
Ok(())
}
#[tokio::test]
async fn daemon_disconnect_exit_summary_includes_reconnect_and_stop_instructions() -> Result<()> {
let (mut app, _, _) = make_test_app_with_channels().await;
@@ -0,0 +1,8 @@
---
source: tui/src/app/tests/background_exit_tests.rs
expression: "render_bottom_popup(&app.chat_widget, 96)"
---
🔒 This conversation is open in another app r to retry
Close it there and press R to continue here.
r retry f fork esc command center ctrl+c/q exit ← transcript
@@ -10,14 +10,18 @@ impl ChatComposer {
self.agents_navigation_enabled = enabled;
}
pub(super) fn agents_navigation_available(&self) -> bool {
pub(crate) fn agents_navigation_key_available(&self) -> bool {
let move_left = if self.draft.textarea.is_vim_normal_mode() {
&self.vim_normal_keymap.move_left
} else {
&self.editor_keymap.move_left
};
move_left.is_pressed(KeyCode::Left.into())
}
pub(super) fn agents_navigation_available(&self) -> bool {
self.agents_navigation_enabled
&& move_left.is_pressed(KeyCode::Left.into())
&& self.agents_navigation_key_available()
&& self.has_focus
&& self.draft.input_enabled
&& self.slash_commands_enabled()
+26
View File
@@ -445,6 +445,32 @@ impl BottomPane {
self.request_redraw();
}
pub(crate) fn agents_navigation_key_available(&self) -> bool {
let left = KeyEvent::from(KeyCode::Left);
self.composer.agents_navigation_key_available()
&& !crate::keymap::keymap_action_ids()
.filter(|action| {
matches!(
action.context,
KeymapContext::Global | KeymapContext::Chat | KeymapContext::Voice
)
})
.any(|action| {
crate::keymap::bindings_for_action(
&self.keymap,
action.context.config_name(),
action.action,
)
.is_some_and(|bindings| bindings.is_pressed(left))
})
&& !self.keymap.chords.bindings.iter().any(|binding| {
matches!(
binding.action.context,
KeymapContext::Global | KeymapContext::Chat | KeymapContext::Voice
) && binding.chord.prefix.is_press(left)
})
}
pub(crate) fn set_task_mentions_enabled(&mut self, enabled: bool) {
self.composer.set_task_mentions_enabled(enabled);
self.request_redraw();
@@ -49,6 +49,10 @@ impl ChatWidget {
self.bottom_pane.set_agents_navigation_enabled(enabled);
}
pub(crate) fn agents_navigation_key_available(&self) -> bool {
self.bottom_pane.agents_navigation_key_available()
}
pub(crate) fn keymap_contexts(&self) -> crate::keymap::KeymapContextSet {
self.bottom_pane.keymap_contexts()
}
+9 -1
View File
@@ -14,6 +14,7 @@ use std::cell::Cell;
struct ExternalWriterNotice {
command_center_available: bool,
agents_navigation_key_available: bool,
transcript_hint: Option<crate::key_hint::ShortcutHint>,
}
@@ -98,7 +99,13 @@ impl ExternalWriterNotice {
crate::key_hint::plain(KeyCode::Char('q')).display_label(),
];
if self.command_center_available {
items.push((escape, "command center".to_string()));
let key = if self.agents_navigation_key_available {
let left = crate::key_hint::plain(KeyCode::Left).display_label();
format!("{left}/{escape}")
} else {
escape
};
items.push((key, "command center".to_string()));
} else {
quit_keys.insert(/*index*/ 0, escape);
}
@@ -221,6 +228,7 @@ impl ChatWidget {
} else if self.external_writer_view && !self.bottom_pane.has_active_view() {
RenderableItem::Owned(Box::new(ExternalWriterNotice {
command_center_available: self.remote_connection.is_some(),
agents_navigation_key_available: self.agents_navigation_key_available(),
transcript_hint: self.bottom_pane.transcript_shortcut_hint(),
}))
} else {
@@ -5,4 +5,4 @@ expression: rendered
🔒 This conversation is open in another app r to retry
Close it there and press R to continue here.
r retry f fork esc command center ctrl+c/q exit ctrl+t transcript
r retry f fork ←/esc command center ctrl+c/q exit ctrl+t transcript
@@ -5,5 +5,5 @@ expression: rendered
🔒 This conversation is open in another app r to retry
Close it there and press R to continue here.
r retry f fork esc command center ctrl+c/q exit
r retry f fork ←/esc command center ctrl+c/q exit
ctrl+t transcript
@@ -5,4 +5,4 @@ expression: "render_bottom_popup(&app.chat_widget, 96)"
🔒 This conversation is open in another app r to retry
Close it there and press R to continue here.
r retry f fork esc command center ctrl+c/q exit ctrl+t transcript
r retry f fork ←/esc command center ctrl+c/q exit ctrl+t transcript