diff --git a/runtime/plugin/nvim_gui_shim.vim b/runtime/plugin/nvim_gui_shim.vim index 319784a..565b2ff 100644 --- a/runtime/plugin/nvim_gui_shim.vim +++ b/runtime/plugin/nvim_gui_shim.vim @@ -1,15 +1,17 @@ " A Neovim plugin that implements GUI helper commands if !has('nvim') || exists('g:GuiLoaded') - finish + finish endif let g:GuiLoaded = 1 if exists('g:GuiInternalClipboard') + let s:LastRegType = 'v' function! provider#clipboard#Call(method, args) abort if a:method == 'get' - return [rpcrequest(1, 'Gui', 'Clipboard', 'Get'), 'v'] + return [rpcrequest(1, 'Gui', 'Clipboard', 'Get', a:args[0]), s:LastRegType] elseif a:method == 'set' - call rpcnotify(1, 'Gui', 'Clipboard', 'Set', join(a:args[0], ' ')) + let s:LastRegType = a:args[1] + call rpcnotify(1, 'Gui', 'Clipboard', 'Set', a:args[2], join(a:args[0], ' ')) endif endfunction endif diff --git a/src/nvim/redraw_handler.rs b/src/nvim/redraw_handler.rs index 40fd59a..9f7122b 100644 --- a/src/nvim/redraw_handler.rs +++ b/src/nvim/redraw_handler.rs @@ -117,7 +117,10 @@ pub fn call_gui_event( "Clipboard" => { match try_str!(args[0]) { "Set" => { - ui.clipboard_set(try_str!(args[1])); + match try_str!(args[1]) { + "*" => ui.clipboard_primary_set(try_str!(args[2])), + _ => ui.clipboard_clipboard_set(try_str!(args[2])), + } }, opt => error!("Unknown option {}", opt), } @@ -162,7 +165,10 @@ pub fn call_gui_request( // mutably twice! let clipboard = { let ui = &mut ui.borrow_mut(); - ui.clipboard.clone() + match try_str!(args[1]) { + "*" => ui.clipboard_primary.clone(), + _ => ui.clipboard_clipboard.clone(), + } }; let t = clipboard.wait_for_text().unwrap_or_else(|| String::new()); Ok(Value::Array(t.split("\n").map(|s| s.into()).collect::>())) diff --git a/src/shell.rs b/src/shell.rs index 5864d16..49593c3 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -59,7 +59,8 @@ pub struct State { cursor: Option, popup_menu: RefCell, settings: Rc>, - pub clipboard: gtk::Clipboard, + pub clipboard_clipboard: gtk::Clipboard, + pub clipboard_primary: gtk::Clipboard, pub mode: mode::Mode, @@ -91,7 +92,8 @@ impl State { cursor: None, popup_menu, settings, - clipboard: gtk::Clipboard::get(&gdk::Atom::intern("CLIPBOARD")), + clipboard_clipboard: gtk::Clipboard::get(&gdk::Atom::intern("CLIPBOARD")), + clipboard_primary: gtk::Clipboard::get(&gdk::Atom::intern("PRIMARY")), mode: mode::Mode::new(), @@ -179,8 +181,12 @@ impl State { } } - pub fn clipboard_set(&self, text: &str) { - self.clipboard.set_text(text); + pub fn clipboard_clipboard_set(&self, text: &str) { + self.clipboard_clipboard.set_text(text); + } + + pub fn clipboard_primary_set(&self, text: &str) { + self.clipboard_primary.set_text(text); } fn close_popup_menu(&self) {