editor: Make buffer search bar capture CopyPath & CopyRelativePath actions (#38645)

Miao created

Closes #38495

Cause:

- When the Find input is focused, CopyPath/CopyRelativePath were handled
by the editor and stopped during the bubble phase, preventing
BufferSearchBar from relaying to the file-backed editor.

Release Notes:

- Fixes “Workspace: Copy Relative Path” not copying while the Find bar
is focused.

Change summary

crates/editor/src/editor.rs        |  4 ++++
crates/search/src/buffer_search.rs | 12 +++++++++++-
2 files changed, 15 insertions(+), 1 deletion(-)

Detailed changes

crates/editor/src/editor.rs đź”—

@@ -19308,6 +19308,8 @@ impl Editor {
             && let Some(path) = path.to_str()
         {
             cx.write_to_clipboard(ClipboardItem::new_string(path.to_string()));
+        } else {
+            cx.propagate();
         }
     }
 
@@ -19321,6 +19323,8 @@ impl Editor {
             && let Some(path) = path.to_str()
         {
             cx.write_to_clipboard(ClipboardItem::new_string(path.to_string()));
+        } else {
+            cx.propagate();
         }
     }
 

crates/search/src/buffer_search.rs đź”—

@@ -28,7 +28,7 @@ use schemars::JsonSchema;
 use serde::Deserialize;
 use settings::Settings;
 use std::sync::Arc;
-use zed_actions::outline::ToggleOutline;
+use zed_actions::{outline::ToggleOutline, workspace::CopyPath, workspace::CopyRelativePath};
 
 use ui::{
     BASE_REM_SIZE_IN_PX, IconButton, IconButtonShape, IconName, Tooltip, h_flex, prelude::*,
@@ -425,6 +425,16 @@ impl Render for BufferSearchBar {
                     active_searchable_item.relay_action(Box::new(ToggleOutline), window, cx);
                 }
             }))
+            .on_action(cx.listener(|this, _: &CopyPath, window, cx| {
+                if let Some(active_searchable_item) = &mut this.active_searchable_item {
+                    active_searchable_item.relay_action(Box::new(CopyPath), window, cx);
+                }
+            }))
+            .on_action(cx.listener(|this, _: &CopyRelativePath, window, cx| {
+                if let Some(active_searchable_item) = &mut this.active_searchable_item {
+                    active_searchable_item.relay_action(Box::new(CopyRelativePath), window, cx);
+                }
+            }))
             .when(replacement, |this| {
                 this.on_action(cx.listener(Self::toggle_replace))
                     .when(in_replace, |this| {