From f5ae905e6bbd3fd8386e64b7fa62c39fd70496d7 Mon Sep 17 00:00:00 2001 From: OnlyYu1996 <1158673577@qq.com> Date: Mon, 18 May 2026 05:15:07 +0800 Subject: [PATCH] fix(tui): route mcp list paste into search --- src/cortex-tui/src/modal/mcp_manager/mod.rs | 38 ++++++++++++++++++++ src/cortex-tui/src/widgets/selection_list.rs | 10 ++++++ 2 files changed, 48 insertions(+) diff --git a/src/cortex-tui/src/modal/mcp_manager/mod.rs b/src/cortex-tui/src/modal/mcp_manager/mod.rs index f95ab7e56..76eb2df61 100644 --- a/src/cortex-tui/src/modal/mcp_manager/mod.rs +++ b/src/cortex-tui/src/modal/mcp_manager/mod.rs @@ -29,6 +29,10 @@ impl Modal for McpManagerModal { fn handle_paste(&mut self, text: &str) -> bool { match &mut self.mode { + McpMode::List => { + self.list.append_search_text(text); + true + } McpMode::AddStdioServer { name, command, @@ -190,3 +194,37 @@ impl Modal for McpManagerModal { Some("Search servers...") } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_list_mode_paste_updates_search_query() { + let mut modal = McpManagerModal::new(vec![ + McpServerInfo { + name: "filesystem".to_string(), + status: McpStatus::Running, + tool_count: 3, + error: None, + requires_auth: false, + }, + McpServerInfo { + name: "github".to_string(), + status: McpStatus::Stopped, + tool_count: 8, + error: None, + requires_auth: false, + }, + ]); + + assert!(modal.handle_paste("git")); + + assert_eq!(modal.list.search_query(), "git"); + assert_eq!(modal.list.filtered_len(), 1); + assert_eq!( + modal.selected_server().map(|server| server.name.as_str()), + Some("github") + ); + } +} diff --git a/src/cortex-tui/src/widgets/selection_list.rs b/src/cortex-tui/src/widgets/selection_list.rs index 162be9585..d06f5c1da 100644 --- a/src/cortex-tui/src/widgets/selection_list.rs +++ b/src/cortex-tui/src/widgets/selection_list.rs @@ -324,6 +324,16 @@ impl SelectionList { &self.search_query } + /// Append text to the current search query and update filtered items. + pub fn append_search_text(&mut self, text: &str) { + if text.is_empty() { + return; + } + + self.search_query.push_str(text); + self.apply_filter(); + } + /// Get the number of filtered items. pub fn filtered_len(&self) -> usize { self.filtered_indices.len()