chore: fix copy/paste on linux
This commit is contained in:
@@ -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({
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
})),
|
||||
|
||||
@@ -1146,6 +1146,9 @@ impl InputState {
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
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<Self>) {
|
||||
#[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<Self>) {
|
||||
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<Self>) {
|
||||
if let Some(clipboard) = cx.read_from_primary() {
|
||||
let mut new_text = clipboard.text().unwrap_or_default();
|
||||
|
||||
if !self.is_multi_line() {
|
||||
|
||||
Reference in New Issue
Block a user