Remove CopyAsMarkdown (#44933)

Michael Benfield created

Copying rendered markdown doesn't reliably do anything sensible. If we
copy text from the middle of a bold section, no formatting is copied. If
we copy text at the end, the trailing bold delimiters are copied,
resulting in gibberish markdown. Thus even fixing the associated issue
(so that leading delimeters are reliably copied) won't consistently
produce good results.

Also, as the user messages in the agent panel don't render markdown
anyway, it seems the most likely use case for copying markdown is
inapplicable.

Closes #42958 

Release Notes:

- N/A

Change summary

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, 5 insertions(+), 23 deletions(-)

Detailed changes

assets/keymaps/default-linux.json 🔗

@@ -262,9 +262,9 @@
   {
     "context": "AgentPanel > Markdown",
     "bindings": {
-      "copy": "markdown::CopyAsMarkdown",
-      "ctrl-insert": "markdown::CopyAsMarkdown",
-      "ctrl-c": "markdown::CopyAsMarkdown",
+      "copy": "markdown::Copy",
+      "ctrl-insert": "markdown::Copy",
+      "ctrl-c": "markdown::Copy",
     },
   },
   {

assets/keymaps/default-macos.json 🔗

@@ -303,7 +303,7 @@
     "context": "AgentPanel > Markdown",
     "use_key_equivalents": true,
     "bindings": {
-      "cmd-c": "markdown::CopyAsMarkdown",
+      "cmd-c": "markdown::Copy",
     },
   },
   {

assets/keymaps/default-windows.json 🔗

@@ -265,7 +265,7 @@
     "context": "AgentPanel > Markdown",
     "use_key_equivalents": true,
     "bindings": {
-      "ctrl-c": "markdown::CopyAsMarkdown",
+      "ctrl-c": "markdown::Copy",
     },
   },
   {

crates/markdown/src/markdown.rs 🔗

@@ -149,8 +149,6 @@ actions!(
     [
         /// Copies the selected text to the clipboard.
         Copy,
-        /// Copies the selected text as markdown to the clipboard.
-        CopyAsMarkdown
     ]
 );
 
@@ -295,14 +293,6 @@ 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;
@@ -1360,14 +1350,6 @@ 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);