From 9b8bc63524a50fba6699558df60e973961618280 Mon Sep 17 00:00:00 2001 From: Danilo Leal <67129314+danilo-leal@users.noreply.github.com> Date: Wed, 17 Dec 2025 09:49:19 -0300 Subject: [PATCH] Revert "Remove CopyAsMarkdown" (#45101) Reverts https://github.com/zed-industries/zed/pull/44933. It turns out that if you're copying agent responses to paste it anywhere else that isn't the message editor (e.g., for a follow up prompt), getting Markdown formatting is helpful. However, with the revert, the underlying issue in https://github.com/zed-industries/zed/issues/42958 remains, so I'll reopen that issue, unfortunately. Release Notes: - N/A --- assets/keymaps/default-linux.json | 6 +++--- assets/keymaps/default-macos.json | 2 +- assets/keymaps/default-windows.json | 2 +- crates/markdown/src/markdown.rs | 18 ++++++++++++++++++ 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/assets/keymaps/default-linux.json b/assets/keymaps/default-linux.json index 1016a20bd6facdc8f5ef9163ebda3e03d451c5cf..f09ac0a812c3e875618c57da15bcf16e1f983d6e 100644 --- a/assets/keymaps/default-linux.json +++ b/assets/keymaps/default-linux.json @@ -264,9 +264,9 @@ { "context": "AgentPanel > Markdown", "bindings": { - "copy": "markdown::Copy", - "ctrl-insert": "markdown::Copy", - "ctrl-c": "markdown::Copy", + "copy": "markdown::CopyAsMarkdown", + "ctrl-insert": "markdown::CopyAsMarkdown", + "ctrl-c": "markdown::CopyAsMarkdown", }, }, { diff --git a/assets/keymaps/default-macos.json b/assets/keymaps/default-macos.json index c80edf01a02347cf678fe9cb24390f2fca41d70e..1d489771febc770e300b63e265024ffca3d14a90 100644 --- a/assets/keymaps/default-macos.json +++ b/assets/keymaps/default-macos.json @@ -306,7 +306,7 @@ "context": "AgentPanel > Markdown", "use_key_equivalents": true, "bindings": { - "cmd-c": "markdown::Copy", + "cmd-c": "markdown::CopyAsMarkdown", }, }, { diff --git a/assets/keymaps/default-windows.json b/assets/keymaps/default-windows.json index dcc828ddf2ef63f3fef6e7e12d9349bead57572e..9154cc43afb86c287329229c6f0d699f59a82b36 100644 --- a/assets/keymaps/default-windows.json +++ b/assets/keymaps/default-windows.json @@ -267,7 +267,7 @@ "context": "AgentPanel > Markdown", "use_key_equivalents": true, "bindings": { - "ctrl-c": "markdown::Copy", + "ctrl-c": "markdown::CopyAsMarkdown", }, }, { diff --git a/crates/markdown/src/markdown.rs b/crates/markdown/src/markdown.rs index 3654418e419bb58f5c9c29ac1baf7172a423156f..706fe894699afe8d1ae32c0525214ec6bf614912 100644 --- a/crates/markdown/src/markdown.rs +++ b/crates/markdown/src/markdown.rs @@ -151,6 +151,8 @@ actions!( [ /// Copies the selected text to the clipboard. Copy, + /// Copies the selected text as markdown to the clipboard. + CopyAsMarkdown ] ); @@ -295,6 +297,14 @@ impl Markdown { cx.write_to_clipboard(ClipboardItem::new_string(text)); } + fn copy_as_markdown(&self, _: &mut Window, cx: &mut Context) { + if self.selection.end <= self.selection.start { + return; + } + let text = self.source[self.selection.start..self.selection.end].to_string(); + cx.write_to_clipboard(ClipboardItem::new_string(text)); + } + fn parse(&mut self, cx: &mut Context) { if self.source.is_empty() { return; @@ -1356,6 +1366,14 @@ impl Element for MarkdownElement { } } }); + window.on_action(std::any::TypeId::of::(), { + let entity = self.markdown.clone(); + move |_, phase, window, cx| { + if phase == DispatchPhase::Bubble { + entity.update(cx, move |this, cx| this.copy_as_markdown(window, cx)) + } + } + }); self.paint_mouse_listeners(hitbox, &rendered_markdown.text, window, cx); rendered_markdown.element.paint(window, cx);