linux: Primary clipboard (#10534)

Implements copying from and pasting to the primary selection.

Release Notes:

- N/A
This commit is contained in:
apricotbucket28 2024-04-18 18:54:18 -03:00 committed by GitHub
parent 98db7fa61e
commit b31df39ab0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 173 additions and 16 deletions

View file

@ -1828,6 +1828,29 @@ impl Editor {
old_cursor_position: &Anchor,
cx: &mut ViewContext<Self>,
) {
// Copy selections to primary selection buffer
#[cfg(target_os = "linux")]
if local {
let selections = self.selections.all::<usize>(cx);
let buffer_handle = self.buffer.read(cx).read(cx);
let mut text = String::new();
for (index, selection) in selections.iter().enumerate() {
let text_for_selection = buffer_handle
.text_for_range(selection.start..selection.end)
.collect::<String>();
text.push_str(&text_for_selection);
if index != selections.len() - 1 {
text.push('\n');
}
}
if !text.is_empty() {
cx.write_to_primary(ClipboardItem::new(text));
}
}
if self.focus_handle.is_focused(cx) && self.leader_peer_id.is_none() {
self.buffer.update(cx, |buffer, cx| {
buffer.set_active_selections(