Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/cortex-tui/src/modal/mcp_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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")
);
}
}
10 changes: 10 additions & 0 deletions src/cortex-tui/src/widgets/selection_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down