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

@ -750,6 +750,11 @@ impl Terminal {
InternalEvent::SetSelection(selection) => {
term.selection = selection.as_ref().map(|(sel, _)| sel.clone());
#[cfg(target_os = "linux")]
if let Some(selection_text) = term.selection_to_string() {
cx.write_to_primary(ClipboardItem::new(selection_text));
}
if let Some((_, head)) = selection {
self.selection_head = Some(*head);
}
@ -766,6 +771,11 @@ impl Terminal {
selection.update(point, side);
term.selection = Some(selection);
#[cfg(target_os = "linux")]
if let Some(selection_text) = term.selection_to_string() {
cx.write_to_primary(ClipboardItem::new(selection_text));
}
self.selection_head = Some(point);
cx.emit(Event::SelectionsChanged)
}
@ -1192,7 +1202,12 @@ impl Terminal {
Some(scroll_delta)
}
pub fn mouse_down(&mut self, e: &MouseDownEvent, origin: Point<Pixels>) {
pub fn mouse_down(
&mut self,
e: &MouseDownEvent,
origin: Point<Pixels>,
cx: &mut ModelContext<Self>,
) {
let position = e.position - origin;
let point = grid_point(
position,
@ -1229,6 +1244,11 @@ impl Terminal {
self.events
.push_back(InternalEvent::SetSelection(Some((sel, point))));
}
} else if e.button == MouseButton::Middle {
if let Some(item) = cx.read_from_primary() {
let text = item.text().to_string();
self.input(text);
}
}
}