Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Allow plugin toggles while searching and preserve filters on refresh (#52200)

Felipe Couryc079352d8380
diff --git a/codex-rs/tui/src/bottom_pane/bottom_pane_view.rs b/codex-rs/tui/src/bottom_pane/bottom_pane_view.rs
index 951e80706b..fe5b341c1f 100644
--- a/codex-rs/tui/src/bottom_pane/bottom_pane_view.rs
+++ b/codex-rs/tui/src/bottom_pane/bottom_pane_view.rs
@@ -69,6 +69,11 @@ pub(crate) trait BottomPaneView: Renderable {
None
}
+ /// Current query for searchable list views that preserve filtering across refreshes.
+ fn search_query(&self) -> Option<&str> {
+ None
+ }
+
/// Apply a matching background suggestion when this view supports text prefills.
fn apply_text_suggestion(
&mut self,
diff --git a/codex-rs/tui/src/bottom_pane/list_selection_view.rs b/codex-rs/tui/src/bottom_pane/list_selection_view.rs
index 64f660f8ac..0ee6a3956d 100644
--- a/codex-rs/tui/src/bottom_pane/list_selection_view.rs
+++ b/codex-rs/tui/src/bottom_pane/list_selection_view.rs
@@ -208,6 +208,8 @@ pub(crate) struct SelectionViewParams {
pub tabs: Vec<SelectionTab>,
pub initial_tab_id: Option<String>,
pub is_searchable: bool,
+ /// Optional non-text key that can toggle a row while printable keys edit the search query.
+ pub search_toggle_key: Option<KeyBinding>,
pub search_placeholder: Option<String>,
pub col_width_mode: ColumnWidthMode,
pub row_display: SelectionRowDisplay,
@@ -268,6 +270,7 @@ impl Default for SelectionViewParams {
tabs: Vec::new(),
initial_tab_id: None,
is_searchable: false,
+ search_toggle_key: None,
search_placeholder: None,
col_width_mode: ColumnWidthMode::AutoVisible,
row_display: SelectionRowDisplay::Wrapped,
@@ -311,6 +314,7 @@ pub(crate) struct ListSelectionView {
pub(super) dismiss_after_child_accept: bool,
pub(super) app_event_tx: AppEventSender,
is_searchable: bool,
+ search_toggle_key: Option<KeyBinding>,
search_query: String,
search_placeholder: Option<String>,
col_width_mode: ColumnWidthMode,
@@ -451,6 +455,7 @@ impl ListSelectionView {
dismiss_after_child_accept: false,
app_event_tx,
is_searchable: params.is_searchable,
+ search_toggle_key: params.search_toggle_key,
search_query: String::new(),
search_placeholder: if params.is_searchable {
params.search_placeholder
@@ -912,9 +917,11 @@ impl ListSelectionView {
}
}
- #[cfg(test)]
pub(crate) fn set_search_query(&mut self, query: String) {
+ let selected_actual_idx = self.selected_actual_idx();
self.search_query = query;
+ self.state.selected_idx = None;
+ self.initial_selected_idx = selected_actual_idx;
self.apply_filter();
}
@@ -1098,6 +1105,14 @@ impl BottomPaneView for ListSelectionView {
!self.is_searchable || !is_plain_text_key_event(key_event);
match key_event {
+ _ if self
+ .search_toggle_key
+ .is_some_and(|key| key.is_press(key_event))
+ && self.keymap.action_for(key_event).is_none()
+ && self.selected_item_has_toggle() =>
+ {
+ self.toggle_selected();
+ }
_ if allow_plain_char_navigation && self.keymap.move_up.is_pressed(key_event) => {
self.move_up()
}
@@ -1247,6 +1262,10 @@ impl BottomPaneView for ListSelectionView {
self.selected_actual_idx()
}
+ fn search_query(&self) -> Option<&str> {
+ self.is_searchable.then_some(self.search_query.as_str())
+ }
+
fn active_tab_id(&self) -> Option<&str> {
ListSelectionView::active_tab_id(self)
}
@@ -2223,6 +2242,54 @@ mod tests {
);
}
+ #[test]
+ fn configured_list_binding_takes_precedence_over_search_toggle_key() {
+ let (tx_raw, mut rx) = unbounded_channel::<AppEvent>();
+ let tx = AppEventSender::new(tx_raw);
+ let mut keymap = crate::keymap::RuntimeKeymap::defaults().list;
+ keymap.move_down = vec![crate::key_hint::plain(KeyCode::Tab)];
+ let mut view = ListSelectionView::new(
+ SelectionViewParams {
+ items: vec![
+ SelectionItem {
+ name: "Plugin".to_string(),
+ toggle: Some(SelectionToggle {
+ is_on: false,
+ action: Box::new(|_enabled, tx: &_| {
+ tx.send(AppEvent::OpenApprovalsPopup);
+ }),
+ }),
+ ..Default::default()
+ },
+ SelectionItem {
+ name: "Next".to_string(),
+ ..Default::default()
+ },
+ ],
+ is_searchable: true,
+ search_toggle_key: Some(crate::key_hint::plain(KeyCode::Tab)),
+ ..Default::default()
+ },
+ tx,
+ keymap,
+ );
+
+ view.handle_key_event(KeyEvent::from(KeyCode::Tab));
+
+ assert_eq!(view.selected_actual_idx(), Some(1));
+ assert!(
+ !view.active_items()[0]
+ .toggle
+ .as_ref()
+ .is_some_and(|toggle| toggle.is_on),
+ "expected the configured move-down binding to leave the toggle unchanged"
+ );
+ assert!(
+ rx.try_recv().is_err(),
+ "expected the configured move-down binding not to fire the toggle action"
+ );
+ }
+
#[test]
fn single_line_row_display_truncates_instead_of_wrapping() {
let (tx_raw, _rx) = unbounded_channel::<AppEvent>();
diff --git a/codex-rs/tui/src/bottom_pane/mod.rs b/codex-rs/tui/src/bottom_pane/mod.rs
index c0e390289e..bc8e6ce08d 100644
--- a/codex-rs/tui/src/bottom_pane/mod.rs
+++ b/codex-rs/tui/src/bottom_pane/mod.rs
@@ -1463,13 +1463,24 @@ impl BottomPane {
return false;
}
+ let search_query = if params.is_searchable {
+ self.view_stack
+ .last()
+ .and_then(|view| view.search_query())
+ .map(str::to_string)
+ } else {
+ None
+ };
self.view_stack.pop();
self.apply_standard_popup_hint(&mut params);
- let view = list_selection_view::ListSelectionView::new(
+ let mut view = list_selection_view::ListSelectionView::new(
params,
self.app_event_tx.clone(),
self.keymap.list.clone(),
);
+ if let Some(search_query) = search_query {
+ view.set_search_query(search_query);
+ }
self.push_view(Box::new(view));
true
}
diff --git a/codex-rs/tui/src/chatwidget/plugin_catalog.rs b/codex-rs/tui/src/chatwidget/plugin_catalog.rs
index 017c4afcd8..79cec717e7 100644
--- a/codex-rs/tui/src/chatwidget/plugin_catalog.rs
+++ b/codex-rs/tui/src/chatwidget/plugin_catalog.rs
@@ -47,6 +47,7 @@ use codex_core_plugins::remote::REMOTE_WORKSPACE_SHARED_WITH_ME_PRIVATE_MARKETPL
use codex_core_plugins::remote::REMOTE_WORKSPACE_SHARED_WITH_ME_UNLISTED_MARKETPLACE_NAME;
use codex_utils_absolute_path::AbsolutePathBuf;
use crossterm::event::KeyCode;
+use crossterm::event::KeyEvent;
use ratatui::buffer::Buffer;
use ratatui::layout::Rect;
use ratatui::prelude::Widget;
@@ -876,7 +877,7 @@ impl ChatWidget {
if can_remove_marketplace || can_upgrade_marketplace {
tab_footer_hints.push((
tab_id.clone(),
- plugins_popup_hint_line(
+ self.plugins_popup_hint_line(
/*can_remove_marketplace*/ can_remove_marketplace,
/*can_upgrade_marketplace*/ can_upgrade_marketplace,
),
@@ -922,7 +923,7 @@ impl ChatWidget {
SelectionViewParams {
view_id: Some(PLUGINS_SELECTION_VIEW_ID),
header: Box::new(()),
- footer_hint: Some(plugins_popup_hint_line(
+ footer_hint: Some(self.plugins_popup_hint_line(
/*can_remove_marketplace*/ false, /*can_upgrade_marketplace*/ false,
)),
tab_footer_hints,
@@ -930,6 +931,7 @@ impl ChatWidget {
reserve_result_rows: true,
initial_tab_id,
is_searchable: true,
+ search_toggle_key: Some(crate::key_hint::plain(KeyCode::Tab)),
search_placeholder: Some("Type to search plugins".to_string()),
col_width_mode: ColumnWidthMode::AutoAllRows,
row_display: SelectionRowDisplay::SingleLine,
@@ -1175,14 +1177,12 @@ impl ChatWidget {
&& plugin.install_policy != PluginInstallPolicy::InstalledByDefault
&& !disabled_by_admin;
let selected_status_label = format!("{status_label:<status_label_width$}");
- let selected_description = if can_toggle_plugin {
+ let selected_description = if can_toggle_plugin && self.plugin_toggle_key_available() {
let toggle_action = if plugin.enabled { "disable" } else { "enable" };
if can_view_details {
- format!(
- "{selected_status_label} Space to {toggle_action}; Enter view details"
- )
+ format!("{selected_status_label} Tab to {toggle_action}; Enter view details")
} else {
- format!("{selected_status_label} Space to {toggle_action}")
+ format!("{selected_status_label} Tab to {toggle_action}")
}
} else if disabled_by_admin && can_view_details {
format!("{selected_status_label} Press Enter to view plugin details")
@@ -1272,25 +1272,38 @@ impl ChatWidget {
}
items
}
-}
-fn plugins_popup_hint_line(
- can_remove_marketplace: bool,
- can_upgrade_marketplace: bool,
-) -> Line<'static> {
- let upgrade = crate::key_hint::ctrl(KeyCode::Char('u')).display_label();
- let remove = crate::key_hint::ctrl(KeyCode::Char('r')).display_label();
- match (can_remove_marketplace, can_upgrade_marketplace) {
- (true, true) => Line::from(format!(
- "{upgrade} upgrade · {remove} remove · space toggle · ←/→ tabs · enter details · esc close",
- )),
- (true, false) => Line::from(format!(
- "{remove} remove · space toggle · ←/→ tabs · enter details · esc close"
- )),
- (false, true) => Line::from(format!(
- "{upgrade} upgrade · space toggle · ←/→ tabs · enter details · esc close"
- )),
- (false, false) => Line::from("←/→ tabs · enter details · space toggle · esc close"),
+ fn plugin_toggle_key_available(&self) -> bool {
+ self.bottom_pane
+ .list_keymap()
+ .action_for(KeyEvent::from(KeyCode::Tab))
+ .is_none()
+ }
+
+ fn plugins_popup_hint_line(
+ &self,
+ can_remove_marketplace: bool,
+ can_upgrade_marketplace: bool,
+ ) -> Line<'static> {
+ let mut hints = Vec::new();
+ if can_upgrade_marketplace {
+ let upgrade = crate::key_hint::ctrl(KeyCode::Char('u')).display_label();
+ hints.push(format!("{upgrade} upgrade"));
+ }
+ if can_remove_marketplace {
+ let remove = crate::key_hint::ctrl(KeyCode::Char('r')).display_label();
+ hints.push(format!("{remove} remove"));
+ }
+ let toggle_key_available = self.plugin_toggle_key_available();
+ if (can_remove_marketplace || can_upgrade_marketplace) && toggle_key_available {
+ hints.push("tab toggle".to_string());
+ }
+ hints.extend(["←/→ tabs", "enter details"].map(str::to_string));
+ if !can_remove_marketplace && !can_upgrade_marketplace && toggle_key_available {
+ hints.push("tab toggle".to_string());
+ }
+ hints.push("esc close".to_string());
+ Line::from(hints.join(" · "))
}
}
diff --git a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__plugins_popup_admin_disabled_installed.snap b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__plugins_popup_admin_disabled_installed.snap
index e6152eb3c9..2406399b43 100644
--- a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__plugins_popup_admin_disabled_installed.snap
+++ b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__plugins_popup_admin_disabled_installed.snap
@@ -19,4 +19,4 @@ expression: popup
- ←/→ tabs · enter details · space toggle · esc close
+ ←/→ tabs · enter details · tab toggle · esc close
diff --git a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__plugins_popup_curated_marketplace.snap b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__plugins_popup_curated_marketplace.snap
index 29ac7869e3..1f52a3cdf0 100644
--- a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__plugins_popup_curated_marketplace.snap
+++ b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__plugins_popup_curated_marketplace.snap
@@ -10,7 +10,7 @@ expression: popup
Type to search plugins
-› [ ] Alpha Sync Disabled Space to enable; Enter view details
+› [ ] Alpha Sync Disabled Tab to enable; Enter view details
[-] Bravo Search Available · OpenAI Curated · Search docs and tickets.
[-] Hidden Repo Plugin Available · Repo Marketplace · Should not be shown in /plugins.
[-] Starter Admin assigned · OpenAI Curated · Included by default.
@@ -19,4 +19,4 @@ expression: popup
- ←/→ tabs · enter details · space toggle · esc close
+ ←/→ tabs · enter details · tab toggle · esc close
diff --git a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__plugins_popup_custom_tab_binding_hides_toggle_hint.snap b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__plugins_popup_custom_tab_binding_hides_toggle_hint.snap
new file mode 100644
index 0000000000..ddfa7e325b
--- /dev/null
+++ b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__plugins_popup_custom_tab_binding_hides_toggle_hint.snap
@@ -0,0 +1,22 @@
+---
+source: tui/src/chatwidget/tests/popups_and_settings.rs
+expression: popup
+---
+ Plugins
+ Browse plugins from available marketplaces.
+ Installed 1 of 1 available plugins.
+
+ All Plugins Installed (1) OpenAI Curated Workspace Add Marketplace
+
+ Type to search plugins
+
+› [*] Drive Installed Press Enter to view plugin details
+
+
+
+
+
+
+
+
+ ←/→ tabs · enter details · esc close
diff --git a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__plugins_popup_empty_shared_section_hidden.snap b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__plugins_popup_empty_shared_section_hidden.snap
index 499988c639..210a9da14d 100644
--- a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__plugins_popup_empty_shared_section_hidden.snap
+++ b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__plugins_popup_empty_shared_section_hidden.snap
@@ -19,4 +19,4 @@ expression: loaded_popup
- ←/→ tabs · enter details · space toggle · esc close
+ ←/→ tabs · enter details · tab toggle · esc close
diff --git a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__plugins_popup_newly_installed_marketplace.snap b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__plugins_popup_newly_installed_marketplace.snap
index 6076d59e37..3b3855cc82 100644
--- a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__plugins_popup_newly_installed_marketplace.snap
+++ b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__plugins_popup_newly_installed_marketplace.snap
@@ -19,4 +19,4 @@ expression: popup
- ⌃u upgrade · ⌃r remove · space toggle · ←/→ tabs · enter details · esc close
+ ⌃u upgrade · ⌃r remove · tab toggle · ←/→ tabs · enter details · esc close
diff --git a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__plugins_popup_search_filtered.snap b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__plugins_popup_search_filtered.snap
index 7aedb6bc0d..cafb800478 100644
--- a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__plugins_popup_search_filtered.snap
+++ b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__plugins_popup_search_filtered.snap
@@ -19,4 +19,4 @@ expression: popup
- ←/→ tabs · enter details · space toggle · esc close
+ ←/→ tabs · enter details · tab toggle · esc close
diff --git a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__plugins_popup_toggle_refresh_preserves_search.snap b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__plugins_popup_toggle_refresh_preserves_search.snap
new file mode 100644
index 0000000000..39d6aa75f7
--- /dev/null
+++ b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__plugins_popup_toggle_refresh_preserves_search.snap
@@ -0,0 +1,22 @@
+---
+source: tui/src/chatwidget/tests/popups_and_settings.rs
+expression: popup
+---
+ Plugins
+ Browse plugins from available marketplaces.
+ Installed 2 of 2 available plugins.
+
+ All Plugins Installed (2) OpenAI Curated Workspace Add Marketplace
+
+ dr
+
+› [*] Drive Installed Tab to disable; Enter view details
+
+
+
+
+
+
+
+
+ ←/→ tabs · enter details · tab toggle · esc close
diff --git a/codex-rs/tui/src/chatwidget/tests/popups_and_settings.rs b/codex-rs/tui/src/chatwidget/tests/popups_and_settings.rs
index 4018a25396..d64fecc640 100644
--- a/codex-rs/tui/src/chatwidget/tests/popups_and_settings.rs
+++ b/codex-rs/tui/src/chatwidget/tests/popups_and_settings.rs
@@ -1157,17 +1157,17 @@ async fn plugins_popup_admin_disabled_installed_plugin_has_no_toggle_hint() {
&& popup.contains("Disabled")
&& popup.contains("Press Enter to view plugin details")
&& !popup.contains("Disabled by admin")
- && !popup.contains("Space to disable"),
+ && !popup.contains("Tab to disable"),
"expected admin-disabled installed row to omit toggle hint, got:\n{popup}"
);
while rx.try_recv().is_ok() {}
let before = render_bottom_popup(&chat, /*width*/ 120);
- chat.handle_key_event(KeyEvent::new(KeyCode::Char(' '), KeyModifiers::NONE));
+ chat.handle_key_event(KeyEvent::from(KeyCode::Tab));
let after = render_bottom_popup(&chat, /*width*/ 120);
assert!(
rx.try_recv().is_err(),
- "space should not toggle admin-disabled installed plugins"
+ "tab should not toggle admin-disabled installed plugins"
);
assert_eq!(after, before);
}
@@ -1633,13 +1633,13 @@ async fn plugins_popup_refreshes_installed_counts_after_install() {
"expected /plugins to refresh installed counts after install, got:\n{after}"
);
assert!(
- after.contains("Installed Space to disable; Enter view details"),
+ after.contains("Installed Tab to disable; Enter view details"),
"expected refreshed selected row copy to reflect the installed plugin state, got:\n{after}"
);
}
#[tokio::test]
-async fn plugins_popup_space_toggles_installed_plugin_from_list() {
+async fn plugins_popup_toggle_keys_preserve_search_and_selection() {
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
chat.set_feature_enabled(Feature::Plugins, /*enabled*/ true);
@@ -1685,17 +1685,68 @@ async fn plugins_popup_space_toggles_installed_plugin_from_list() {
other => panic!("expected SetPluginEnabled event, got {other:?}"),
}
+ type_plugins_search_query(&mut chat, "dr");
+ chat.handle_key_event(KeyEvent::from(KeyCode::Tab));
+
+ match rx.try_recv() {
+ Ok(AppEvent::SetPluginEnabled {
+ cwd: event_cwd,
+ plugin_id,
+ enabled,
+ }) => {
+ assert_eq!(event_cwd, cwd);
+ assert_eq!(plugin_id, "plugin-drive");
+ assert!(enabled);
+ }
+ other => panic!("expected SetPluginEnabled event, got {other:?}"),
+ }
+
chat.on_plugin_enabled_set(
cwd,
"plugin-drive".to_string(),
- /*enabled*/ false,
+ /*enabled*/ true,
Ok(()),
);
let popup = render_bottom_popup(&chat, /*width*/ 100);
+ assert_chatwidget_snapshot!("plugins_popup_toggle_refresh_preserves_search", popup);
+ assert!(
+ popup.lines().any(|line| line.trim() == "dr")
+ && popup.contains("› [*] Drive")
+ && popup.contains("Tab to disable"),
+ "expected the filtered plugin and search query to survive refresh, got:\n{popup}"
+ );
+}
+
+#[tokio::test]
+async fn plugins_popup_hides_tab_toggle_hint_when_tab_is_configured() {
+ let (mut chat, _rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
+ chat.set_feature_enabled(Feature::Plugins, /*enabled*/ true);
+ let mut keymap = crate::keymap::RuntimeKeymap::defaults();
+ keymap.list.move_down = vec![crate::key_hint::plain(KeyCode::Tab)];
+ chat.bottom_pane.set_keymap_bindings(&keymap);
+
+ let popup = render_loaded_plugins_popup(
+ &mut chat,
+ plugins_test_response(vec![plugins_test_curated_marketplace(vec![
+ plugins_test_summary(
+ "plugin-drive",
+ "drive",
+ Some("Drive"),
+ Some("Document access."),
+ /*installed*/ true,
+ /*enabled*/ true,
+ PluginInstallPolicy::Available,
+ ),
+ ])]),
+ );
+
+ assert_chatwidget_snapshot!("plugins_popup_custom_tab_binding_hides_toggle_hint", popup);
assert!(
- popup.contains("› [ ] Drive"),
- "expected selected plugin row to stay selected after refresh, got:\n{popup}"
+ popup.contains("Installed Press Enter to view plugin details")
+ && !popup.contains("Tab to disable")
+ && !popup.contains("tab toggle"),
+ "expected configured Tab binding to hide unavailable toggle hints, got:\n{popup}"
);
}