From 7c0d9f411a4964b774532f9aae582ef00cedb986 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Thu, 7 Jul 2022 13:19:38 -0700 Subject: [PATCH] Added copying --- assets/keymaps/default.json | 3 ++- crates/terminal/src/terminal.rs | 13 ++++++++++++- pbcpoy | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 pbcpoy diff --git a/assets/keymaps/default.json b/assets/keymaps/default.json index bea53ece45b2a672879453bb522fd64814e635f3..6cd3660bf5120d4b16f1f6988588a537b7b92a31 100644 --- a/assets/keymaps/default.json +++ b/assets/keymaps/default.json @@ -417,7 +417,8 @@ "up": "terminal::Up", "down": "terminal::Down", "tab": "terminal::Tab", - "cmd-v": "terminal::Paste" + "cmd-v": "terminal::Paste", + "cmd-c": "terminal::Copy" } } ] \ No newline at end of file diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rs index dbbd1341e653598669c26949c62a81b6cc61414a..133edcd9067ffda1d74e3c0e7d6f3a340f8fe87c 100644 --- a/crates/terminal/src/terminal.rs +++ b/crates/terminal/src/terminal.rs @@ -53,7 +53,7 @@ pub struct ScrollTerminal(pub i32); actions!( terminal, - [Sigint, Escape, Del, Return, Left, Right, Up, Down, Tab, Clear, Paste, Deploy, Quit] + [Sigint, Escape, Del, Return, Left, Right, Up, Down, Tab, Clear, Copy, Paste, Deploy, Quit] ); impl_internal_actions!(terminal, [Input, ScrollTerminal]); @@ -71,6 +71,7 @@ pub fn init(cx: &mut MutableAppContext) { cx.add_action(Terminal::up); cx.add_action(Terminal::down); cx.add_action(Terminal::tab); + cx.add_action(Terminal::copy); cx.add_action(Terminal::paste); cx.add_action(Terminal::scroll_terminal); } @@ -275,6 +276,16 @@ impl Terminal { cx.emit(Event::CloseTerminal); } + ///Attempt to paste the clipboard into the terminal + fn copy(&mut self, _: &Copy, cx: &mut ViewContext) { + let term = self.term.lock(); + let copy_text = term.selection_to_string(); + match copy_text { + Some(s) => cx.write_to_clipboard(ClipboardItem::new(s)), + None => (), + } + } + ///Attempt to paste the clipboard into the terminal fn paste(&mut self, _: &Paste, cx: &mut ViewContext) { if let Some(item) = cx.read_from_clipboard() { diff --git a/pbcpoy b/pbcpoy new file mode 100644 index 0000000000000000000000000000000000000000..f70f10e4db19068f79bc43844b49f3eece45c4e8 --- /dev/null +++ b/pbcpoy @@ -0,0 +1 @@ +A