From 204c666f9101b76a6293a8062844e8b0ffc8a756 Mon Sep 17 00:00:00 2001 From: Mattias Eriksson Date: Sat, 20 Jan 2024 14:13:04 +0100 Subject: [PATCH] Add support for Primary --- src/main.rs | 20 ++++++++++++++++++++ src/terminal_box.rs | 14 +++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index aa3b12f..bbe6a28 100644 --- a/src/main.rs +++ b/src/main.rs @@ -213,6 +213,8 @@ pub enum Message { PaneResized(pane_grid::ResizeEvent), Modifiers(Modifiers), Paste(Option), + #[cfg(target_family = "unix")] + PastePrimary(Option), PasteValue(Option, String), SelectAll(Option), UseBrightBold(bool), @@ -1038,6 +1040,13 @@ impl Application for App { None => message::none(), }); } + #[cfg(target_family = "unix")] + Message::PastePrimary(entity_opt) => { + return clipboard::read_primary(move |value_opt| match value_opt { + Some(value) => message::app(Message::PasteValue(entity_opt, value)), + None => message::none(), + }); + } Message::PasteValue(entity_opt, value) => { if let Some(tab_model) = self.pane_model.active() { let entity = entity_opt.unwrap_or_else(|| tab_model.active()); @@ -1622,6 +1631,17 @@ impl Application for App { None } } + #[cfg(target_family = "unix")] + Event::Keyboard(KeyEvent::KeyPressed { + key_code: KeyCode::Insert, + modifiers, + }) => { + if modifiers == Modifiers::SHIFT { + Some(Message::PastePrimary(None)) + } else { + None + } + } Event::Keyboard(KeyEvent::KeyPressed { key_code: KeyCode::Equals, modifiers, diff --git a/src/terminal_box.rs b/src/terminal_box.rs index 6d06515..af383af 100644 --- a/src/terminal_box.rs +++ b/src/terminal_box.rs @@ -575,7 +575,7 @@ where layout: Layout<'_>, cursor_position: mouse::Cursor, _renderer: &Renderer, - _clipboard: &mut dyn Clipboard, + clipboard: &mut dyn Clipboard, shell: &mut Shell<'_, Message>, _viewport: &Rectangle, ) -> Status { @@ -977,6 +977,11 @@ where } } } + } else if let Button::Middle = button { + #[cfg(target_family = "unix")] + if let Some(value) = clipboard.read_primary() { + terminal.input_scroll(value.as_bytes().to_vec()); + } } // Update context menu state @@ -994,6 +999,13 @@ where } } Event::Mouse(MouseEvent::ButtonReleased(Button::Left)) => { + #[cfg(target_family = "unix")] + if let Some(Dragging::Buffer) = state.dragging { + let term = terminal.term.lock(); + if let Some(text) = term.selection_to_string() { + clipboard.write_primary(text); + } + } state.dragging = None; status = Status::Captured; }