chore: fix copy/paste on linux

This commit is contained in:
2025-07-02 15:53:52 +07:00
parent 2e046ec5d7
commit f9bf29df09
3 changed files with 19 additions and 18 deletions

View File

@@ -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() {