Add CopyOrSigint shortcut for Ctrl+C

This commit is contained in:
Rajas Paranjpe 2024-05-03 14:37:01 -07:00 committed by Jeremy Soller
parent ec58819a68
commit b7b3e942fa
2 changed files with 24 additions and 0 deletions

View file

@ -168,6 +168,7 @@ pub enum Action {
About,
ColorSchemes(ColorSchemeKind),
Copy,
CopyOrSigint,
CopyPrimary,
Find,
PaneFocusDown,
@ -214,6 +215,7 @@ impl MenuAction for Action {
Message::ToggleContextPage(ContextPage::ColorSchemes(*color_scheme_kind))
}
Self::Copy => Message::Copy(entity_opt),
Self::CopyOrSigint => Message::CopyOrSigint(entity_opt),
Self::CopyPrimary => Message::CopyPrimary(entity_opt),
Self::Find => Message::Find(true),
Self::PaneFocusDown => Message::PaneFocusAdjacent(pane_grid::Direction::Down),
@ -268,6 +270,7 @@ pub enum Message {
ColorSchemeTabActivate(widget::segmented_button::Entity),
Config(Config),
Copy(Option<segmented_button::Entity>),
CopyOrSigint(Option<segmented_button::Entity>),
CopyPrimary(Option<segmented_button::Entity>),
DefaultBoldFontWeight(usize),
DefaultDimFontWeight(usize),
@ -1676,6 +1679,26 @@ impl Application for App {
}
return self.update_focus();
}
Message::CopyOrSigint(entity_opt) => {
if let Some(tab_model) = self.pane_model.active() {
let entity = entity_opt.unwrap_or_else(|| tab_model.active());
if let Some(terminal) = tab_model.data::<Mutex<Terminal>>(entity) {
let terminal = terminal.lock().unwrap();
let term = terminal.term.lock();
if let Some(text) = term.selection_to_string() {
return Command::batch([clipboard::write(text), self.update_focus()]);
} else {
// Drop the lock for term so that input_scroll doesn't block forever
drop(term);
// 0x03 is ^C
terminal.input_scroll(&[0x03]);
}
}
} else {
log::warn!("Failed to get focused pane");
}
return self.update_focus();
}
Message::CopyPrimary(entity_opt) => {
if let Some(tab_model) = self.pane_model.active() {
let entity = entity_opt.unwrap_or_else(|| tab_model.active());