Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Revert "Remove CopyAsMarkdown" (#45101)

Danilo Leal9b8bc63524a5
diff --git a/assets/keymaps/default-linux.json b/assets/keymaps/default-linux.json
index 1016a20bd6f..f09ac0a812c 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 c80edf01a02..1d489771feb 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 dcc828ddf2e..9154cc43afb 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 3654418e419..706fe894699 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<Self>) {
+ 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<Self>) {
if self.source.is_empty() {
return;
@@ -1356,6 +1366,14 @@ impl Element for MarkdownElement {
}
}
});
+ window.on_action(std::any::TypeId::of::<crate::CopyAsMarkdown>(), {
+ 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);