Add support for Primary
This commit is contained in:
parent
2a020221fd
commit
204c666f91
2 changed files with 33 additions and 1 deletions
20
src/main.rs
20
src/main.rs
|
|
@ -213,6 +213,8 @@ pub enum Message {
|
|||
PaneResized(pane_grid::ResizeEvent),
|
||||
Modifiers(Modifiers),
|
||||
Paste(Option<segmented_button::Entity>),
|
||||
#[cfg(target_family = "unix")]
|
||||
PastePrimary(Option<segmented_button::Entity>),
|
||||
PasteValue(Option<segmented_button::Entity>, String),
|
||||
SelectAll(Option<segmented_button::Entity>),
|
||||
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,
|
||||
|
|
|
|||
|
|
@ -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<f32>,
|
||||
) -> 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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue