Skip to content
Merged
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
40 changes: 40 additions & 0 deletions cortex-tui/src/modal/mcp_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,46 @@ impl Modal for McpManagerModal {
"MCP Servers"
}

fn handle_paste(&mut self, text: &str) -> bool {
match &mut self.mode {
McpMode::AddStdioServer {
name,
command,
args,
focus,
} => {
match focus {
AddStdioServerFocus::Name => name.push_str(text),
AddStdioServerFocus::Command => command.push_str(text),
AddStdioServerFocus::Args => args.push_str(text),
}
true
}
McpMode::AddHttpServer { name, url, focus } => {
match focus {
AddHttpServerFocus::Name => name.push_str(text),
AddHttpServerFocus::Url => url.push_str(text),
}
true
}
McpMode::SetAuth {
server_name: _,
api_key,
} => {
api_key.push_str(text);
true
}
McpMode::SelectFromRegistry {
selected: _,
search_query,
} => {
search_query.push_str(text);
true
}
_ => false,
}
}

fn desired_height(&self, max_height: u16, _width: u16) -> u16 {
match &self.mode {
McpMode::List => {
Expand Down
16 changes: 16 additions & 0 deletions cortex-tui/src/modal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ pub trait Modal: Send {
/// Handle a key event, returning the result
fn handle_key(&mut self, key: KeyEvent) -> ModalResult;

/// Handle pasted text. Returns true if the paste was handled.
/// Default implementation does nothing.
fn handle_paste(&mut self, _text: &str) -> bool {
false
}

/// Key hints to display at the bottom
fn key_hints(&self) -> Vec<(&'static str, &'static str)>;

Expand Down Expand Up @@ -243,6 +249,16 @@ impl ModalStack {
}
}

/// Handle pasted text, delegating to the top modal
/// Returns true if the paste was handled
pub fn handle_paste(&mut self, text: &str) -> bool {
if let Some(modal) = self.current_mut() {
modal.handle_paste(text)
} else {
false
}
}

/// Clear all modals from the stack
pub fn clear(&mut self) {
self.stack.clear();
Expand Down
7 changes: 5 additions & 2 deletions cortex-tui/src/runner/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1672,10 +1672,13 @@ impl EventLoop {
}

EngineEvent::Paste(text) => {
// Check if a form modal is active and route paste to it
if let Some(crate::app::ActiveModal::Form(ref mut form_state)) =
// Check modal stack first (unified modal system)
if self.modal_stack.is_active() && self.modal_stack.handle_paste(&text) {
// Paste was handled by modal
} else if let Some(crate::app::ActiveModal::Form(ref mut form_state)) =
self.app_state.active_modal
{
// Check if a form modal is active and route paste to it
form_state.handle_paste(&text);
} else {
// Otherwise insert pasted text into the main input widget
Expand Down
Loading