Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Preserve slash command order in search (#9425)

Ahmed Ibrahimaeaff26451ec
diff --git a/codex-rs/tui/src/bottom_pane/command_popup.rs b/codex-rs/tui/src/bottom_pane/command_popup.rs
index ec4e86af03..10a469c683 100644
--- a/codex-rs/tui/src/bottom_pane/command_popup.rs
+++ b/codex-rs/tui/src/bottom_pane/command_popup.rs
@@ -113,8 +113,8 @@ impl CommandPopup {
}
/// Compute fuzzy-filtered matches over built-in commands and user prompts,
- /// paired with optional highlight indices and score. Sorted by ascending
- /// score, then by name for stability.
+ /// paired with optional highlight indices and score. Preserves the original
+ /// presentation order for built-ins and prompts.
fn filtered(&self) -> Vec<(CommandItem, Option<Vec<usize>>, i32)> {
let filter = self.command_filter.trim();
let mut out: Vec<(CommandItem, Option<Vec<usize>>, i32)> = Vec::new();
@@ -144,20 +144,6 @@ impl CommandPopup {
out.push((CommandItem::UserPrompt(idx), Some(indices), score));
}
}
- // When filtering, sort by ascending score and then by name for stability.
- out.sort_by(|a, b| {
- a.2.cmp(&b.2).then_with(|| {
- let an = match a.0 {
- CommandItem::Builtin(c) => c.command(),
- CommandItem::UserPrompt(i) => &self.prompts[i].name,
- };
- let bn = match b.0 {
- CommandItem::Builtin(c) => c.command(),
- CommandItem::UserPrompt(i) => &self.prompts[i].name,
- };
- an.cmp(bn)
- })
- });
out
}
@@ -292,6 +278,32 @@ mod tests {
}
}
+ #[test]
+ fn filtered_commands_keep_presentation_order() {
+ let mut popup = CommandPopup::new(Vec::new(), false);
+ popup.on_composer_text_change("/m".to_string());
+
+ let cmds: Vec<&str> = popup
+ .filtered_items()
+ .into_iter()
+ .filter_map(|item| match item {
+ CommandItem::Builtin(cmd) => Some(cmd.command()),
+ CommandItem::UserPrompt(_) => None,
+ })
+ .collect();
+ assert_eq!(
+ cmds,
+ vec![
+ "model",
+ "experimental",
+ "resume",
+ "compact",
+ "mention",
+ "mcp"
+ ]
+ );
+ }
+
#[test]
fn prompt_discovery_lists_custom_prompts() {
let prompts = vec![
diff --git a/codex-rs/tui2/src/bottom_pane/command_popup.rs b/codex-rs/tui2/src/bottom_pane/command_popup.rs
index 2fee23f1b6..ba49ab12c0 100644
--- a/codex-rs/tui2/src/bottom_pane/command_popup.rs
+++ b/codex-rs/tui2/src/bottom_pane/command_popup.rs
@@ -113,8 +113,8 @@ impl CommandPopup {
}
/// Compute fuzzy-filtered matches over built-in commands and user prompts,
- /// paired with optional highlight indices and score. Sorted by ascending
- /// score, then by name for stability.
+ /// paired with optional highlight indices and score. Preserves the original
+ /// presentation order for built-ins and prompts.
fn filtered(&self) -> Vec<(CommandItem, Option<Vec<usize>>, i32)> {
let filter = self.command_filter.trim();
let mut out: Vec<(CommandItem, Option<Vec<usize>>, i32)> = Vec::new();
@@ -144,20 +144,6 @@ impl CommandPopup {
out.push((CommandItem::UserPrompt(idx), Some(indices), score));
}
}
- // When filtering, sort by ascending score and then by name for stability.
- out.sort_by(|a, b| {
- a.2.cmp(&b.2).then_with(|| {
- let an = match a.0 {
- CommandItem::Builtin(c) => c.command(),
- CommandItem::UserPrompt(i) => &self.prompts[i].name,
- };
- let bn = match b.0 {
- CommandItem::Builtin(c) => c.command(),
- CommandItem::UserPrompt(i) => &self.prompts[i].name,
- };
- an.cmp(bn)
- })
- });
out
}
@@ -291,6 +277,22 @@ mod tests {
}
}
+ #[test]
+ fn filtered_commands_keep_presentation_order() {
+ let mut popup = CommandPopup::new(Vec::new(), false);
+ popup.on_composer_text_change("/m".to_string());
+
+ let cmds: Vec<&str> = popup
+ .filtered_items()
+ .into_iter()
+ .filter_map(|item| match item {
+ CommandItem::Builtin(cmd) => Some(cmd.command()),
+ CommandItem::UserPrompt(_) => None,
+ })
+ .collect();
+ assert_eq!(cmds, vec!["model", "resume", "compact", "mention", "mcp"]);
+ }
+
#[test]
fn prompt_discovery_lists_custom_prompts() {
let prompts = vec![