Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Support path pasting in terminal (#48222)
George Waters4b3c0cda73fa
diff --git a/assets/keymaps/default-macos.json b/assets/keymaps/default-macos.jsonindex 8e115985db8..d73c6d7a8b6 100644--- a/assets/keymaps/default-macos.json+++ b/assets/keymaps/default-macos.json@@ -1264,6 +1264,7 @@"ctrl-cmd-space": "terminal::ShowCharacterPalette","cmd-c": "terminal::Copy","cmd-v": "terminal::Paste",+ "ctrl-cmd-v": "terminal::PasteText","cmd-f": "buffer_search::Deploy","cmd-a": "editor::SelectAll","cmd-k": "terminal::Clear",diff --git a/assets/keymaps/default-windows.json b/assets/keymaps/default-windows.jsonindex 9ac7ed46cfd..fc1d78b39f2 100644--- a/assets/keymaps/default-windows.json+++ b/assets/keymaps/default-windows.json@@ -1221,6 +1221,7 @@"shift-insert": "terminal::Paste","ctrl-v": "terminal::Paste","ctrl-shift-v": "terminal::Paste",+ "ctrl-alt-v": "terminal::PasteText","ctrl-i": "assistant::InlineAssist","alt-b": ["terminal::SendText", "\u001bb"],"alt-f": ["terminal::SendText", "\u001bf"],diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rsindex 3be023e8262..99b3b9d6ce4 100644--- a/crates/terminal/src/terminal.rs+++ b/crates/terminal/src/terminal.rs@@ -84,6 +84,8 @@ actions!(Copy,/// Pastes from the clipboard.Paste,+ /// Pastes the text from the clipboard.+ PasteText,/// Shows the character palette for special characters.ShowCharacterPalette,/// Searches for text in the terminal.diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rsindex 36bac033123..a6e28a95f50 100644--- a/crates/terminal_view/src/terminal_view.rs+++ b/crates/terminal_view/src/terminal_view.rs@@ -32,9 +32,9 @@ use std::{};use task::TaskId;use terminal::{- Clear, Copy, Event, HoveredWord, MaybeNavigationTarget, Paste, ScrollLineDown, ScrollLineUp,- ScrollPageDown, ScrollPageUp, ScrollToBottom, ScrollToTop, ShowCharacterPalette, TaskState,- TaskStatus, Terminal, TerminalBounds, ToggleViMode,+ Clear, Copy, Event, HoveredWord, MaybeNavigationTarget, Paste, PasteText, ScrollLineDown,+ ScrollLineUp, ScrollPageDown, ScrollPageUp, ScrollToBottom, ScrollToTop, ShowCharacterPalette,+ TaskState, TaskStatus, Terminal, TerminalBounds, ToggleViMode,alacritty_terminal::{index::Point as AlacPoint,term::{TermMode, point_to_viewport, search::RegexSearch},@@ -508,6 +508,7 @@ impl TerminalView {.separator().action("Copy", Box::new(Copy)).action("Paste", Box::new(Paste))+ .action("Paste Text", Box::new(PasteText)).action("Select All", Box::new(SelectAll)).action("Clear", Box::new(Clear)).when(assistant_enabled, |menu| {@@ -811,7 +812,7 @@ impl TerminalView {}///Attempt to paste the clipboard into the terminal- fn paste(&mut self, _: &Paste, _: &mut Window, cx: &mut Context<Self>) {+ fn paste(&mut self, _: &Paste, window: &mut Window, cx: &mut Context<Self>) {let Some(clipboard) = cx.read_from_clipboard() else {return;};@@ -820,6 +821,9 @@ impl TerminalView {Some(ClipboardEntry::Image(image)) if !image.bytes.is_empty() => {self.forward_ctrl_v(cx);}+ Some(ClipboardEntry::ExternalPaths(paths)) => {+ self.add_paths_to_terminal(paths.paths(), window, cx);+ }_ => {if let Some(text) = clipboard.text() {self.terminal@@ -829,6 +833,18 @@ impl TerminalView {}}+ ///Attempt to paste the clipboard text into the terminal+ fn paste_text(&mut self, _: &PasteText, _: &mut Window, cx: &mut Context<Self>) {+ let Some(clipboard) = cx.read_from_clipboard() else {+ return;+ };++ if let Some(text) = clipboard.text() {+ self.terminal+ .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>) {@@ -1226,6 +1242,7 @@ impl Render for TerminalView {.on_action(cx.listener(TerminalView::send_keystroke)).on_action(cx.listener(TerminalView::copy)).on_action(cx.listener(TerminalView::paste))+ .on_action(cx.listener(TerminalView::paste_text)).on_action(cx.listener(TerminalView::clear)).on_action(cx.listener(TerminalView::scroll_line_up)).on_action(cx.listener(TerminalView::scroll_line_down))