diff --git a/crates/coop/src/views/chat.rs b/crates/coop/src/views/chat.rs index 52aa248..313caa0 100644 --- a/crates/coop/src/views/chat.rs +++ b/crates/coop/src/views/chat.rs @@ -722,10 +722,7 @@ impl Chat { .on_click({ let content = ClipboardItem::new_string(message.content.to_string()); cx.listener(move |_this, _event, _window, cx| { - #[cfg(any(target_os = "linux", target_os = "freebsd"))] - cx.write_to_primary(content.clone()); - #[cfg(any(target_os = "windows", target_os = "macos"))] - cx.write_to_clipboard(content.clone()); + cx.write_to_clipboard(content.clone()) }) }), ], @@ -734,10 +731,7 @@ impl Chat { .on_mouse_down(gpui::MouseButton::Middle, { let content = ClipboardItem::new_string(message.content.to_string()); cx.listener(move |_this, _event, _window, cx| { - #[cfg(any(target_os = "linux", target_os = "freebsd"))] - cx.write_to_primary(content.clone()); - #[cfg(any(target_os = "windows", target_os = "macos"))] - cx.write_to_clipboard(content.clone()); + cx.write_to_clipboard(content.clone()) }) }) .on_double_click(cx.listener({ diff --git a/crates/coop/src/views/sidebar/mod.rs b/crates/coop/src/views/sidebar/mod.rs index a8fb465..32c5b1e 100644 --- a/crates/coop/src/views/sidebar/mod.rs +++ b/crates/coop/src/views/sidebar/mod.rs @@ -527,11 +527,7 @@ impl Sidebar { let item = ClipboardItem::new_string(public_key); move |_, _, window, cx| { - #[cfg(any(target_os = "linux", target_os = "freebsd"))] - cx.write_to_primary(item.clone()); - #[cfg(any(target_os = "windows", target_os = "macos"))] cx.write_to_clipboard(item.clone()); - window.push_notification("User's NPUB is copied", cx); } })), diff --git a/crates/ui/src/input/state.rs b/crates/ui/src/input/state.rs index cc630da..bfe8db2 100644 --- a/crates/ui/src/input/state.rs +++ b/crates/ui/src/input/state.rs @@ -1146,6 +1146,9 @@ impl InputState { cx: &mut Context, ) { if event.button == MouseButton::Middle { + #[cfg(any(target_os = "linux", target_os = "freebsd"))] + self.paste_from_primary(window, cx); + #[cfg(not(any(target_os = "linux", target_os = "freebsd")))] self.paste(&Paste, window, cx); return; } @@ -1228,13 +1231,21 @@ impl InputState { self.replace_text_in_range(None, "", window, cx); } - pub(super) fn paste(&mut self, _paste: &Paste, window: &mut Window, cx: &mut Context) { - #[cfg(any(target_os = "linux", target_os = "freebsd"))] - let read_clipboard = cx.read_from_primary(); - #[cfg(any(target_os = "macos", target_os = "windows"))] - let read_clipboard = cx.read_from_clipboard(); + pub(super) fn paste(&mut self, _: &Paste, window: &mut Window, cx: &mut Context) { + if let Some(clipboard) = cx.read_from_clipboard() { + let mut new_text = clipboard.text().unwrap_or_default(); - if let Some(clipboard) = read_clipboard { + if !self.is_multi_line() { + new_text = new_text.replace('\n', ""); + } + + self.replace_text_in_range(None, &new_text, window, cx); + } + } + + #[cfg(any(target_os = "linux", target_os = "freebsd"))] + pub(super) fn paste_from_primary(&mut self, window: &mut Window, cx: &mut Context) { + if let Some(clipboard) = cx.read_from_primary() { let mut new_text = clipboard.text().unwrap_or_default(); if !self.is_multi_line() {