diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rs index 54808934ba7b098a695a8b104a048a379966e6f1..e7e60ff4b31dfbdd16b7de8841285d81fc311fc5 100644 --- a/crates/terminal_view/src/terminal_view.rs +++ b/crates/terminal_view/src/terminal_view.rs @@ -8,8 +8,8 @@ mod terminal_slash_command; use assistant_slash_command::SlashCommandRegistry; use editor::{EditorSettings, actions::SelectAll, blink_manager::BlinkManager}; use gpui::{ - Action, AnyElement, App, DismissEvent, Entity, EventEmitter, FocusHandle, Focusable, - KeyContext, KeyDownEvent, Keystroke, MouseButton, MouseDownEvent, Pixels, Render, + Action, AnyElement, App, ClipboardEntry, DismissEvent, Entity, EventEmitter, FocusHandle, + Focusable, KeyContext, KeyDownEvent, Keystroke, MouseButton, MouseDownEvent, Pixels, Render, ScrollWheelEvent, Styled, Subscription, Task, WeakEntity, actions, anchored, deferred, div, }; use persistence::TERMINAL_DB; @@ -687,12 +687,32 @@ impl TerminalView { ///Attempt to paste the clipboard into the terminal fn paste(&mut self, _: &Paste, _: &mut Window, cx: &mut Context) { - if let Some(clipboard_string) = cx.read_from_clipboard().and_then(|item| item.text()) { + let Some(clipboard) = cx.read_from_clipboard() else { + return; + }; + + if clipboard.entries().iter().any(|entry| match entry { + ClipboardEntry::Image(image) => !image.bytes.is_empty(), + _ => false, + }) { + self.forward_ctrl_v(cx); + return; + } + + if let Some(text) = clipboard.text() { self.terminal - .update(cx, |terminal, _cx| terminal.paste(&clipboard_string)); + .update(cx, |terminal, _cx| terminal.paste(&text)); } } + /// Emits a raw Ctrl+V so TUI agents can read the OS clipboard directly + /// and attach images using their native workflows. + fn forward_ctrl_v(&self, cx: &mut Context) { + self.terminal.update(cx, |term, _| { + term.input(vec![0x16]); + }); + } + fn send_text(&mut self, text: &SendText, _: &mut Window, cx: &mut Context) { self.clear_bell(cx); self.terminal.update(cx, |term, _| {