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

@ -502,6 +502,34 @@ impl EditorElement {
cx.stop_propagation();
}
fn mouse_middle_down(
editor: &mut Editor,
event: &MouseDownEvent,
position_map: &PositionMap,
text_hitbox: &Hitbox,
cx: &mut ViewContext<Editor>,
) {
if !text_hitbox.is_hovered(cx) || editor.read_only(cx) {
return;
}
if let Some(item) = cx.read_from_primary() {
let point_for_position =
position_map.point_for_position(text_hitbox.bounds, event.position);
let position = point_for_position.previous_valid;
editor.select(
SelectPhase::Begin {
position,
add: false,
click_count: 1,
},
cx,
);
editor.insert(item.text(), cx);
}
}
fn mouse_up(
editor: &mut Editor,
event: &MouseUpEvent,
@ -2903,6 +2931,9 @@ impl EditorElement {
MouseButton::Right => editor.update(cx, |editor, cx| {
Self::mouse_right_down(editor, event, &position_map, &text_hitbox, cx);
}),
MouseButton::Middle => editor.update(cx, |editor, cx| {
Self::mouse_middle_down(editor, event, &position_map, &text_hitbox, cx);
}),
_ => {}
};
}