From 53516f0d9c324835154be72dd34dd035feb1fbef Mon Sep 17 00:00:00 2001 From: Greg V Date: Tue, 2 Jan 2018 22:38:35 +0300 Subject: [PATCH 1/2] Add support for PRIMARY clipboard --- runtime/plugin/nvim_gui_shim.vim | 6 +++--- src/nvim/redraw_handler.rs | 10 ++++++++-- src/shell.rs | 14 ++++++++++---- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/runtime/plugin/nvim_gui_shim.vim b/runtime/plugin/nvim_gui_shim.vim index 319784a..f60d293 100644 --- a/runtime/plugin/nvim_gui_shim.vim +++ b/runtime/plugin/nvim_gui_shim.vim @@ -1,15 +1,15 @@ " 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') 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]), 'v'] elseif a:method == 'set' - call rpcnotify(1, 'Gui', 'Clipboard', 'Set', join(a:args[0], ' ')) + 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 cb4980e..da91be3 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(), @@ -178,8 +180,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) { From 87dafda473e343de1a271462c514fc9710ed3180 Mon Sep 17 00:00:00 2001 From: Greg V Date: Wed, 3 Jan 2018 15:49:10 +0300 Subject: [PATCH 2/2] Store last clipboard register type This makes `yy` -> `p` line copying work correctly, but whether external text would be pasted as whole lines or not now depends on the last copy operation. The proper implementation would store the register type in the actual Gtk clipboard, but gtk-rs is not ready for that yet. --- runtime/plugin/nvim_gui_shim.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/runtime/plugin/nvim_gui_shim.vim b/runtime/plugin/nvim_gui_shim.vim index f60d293..565b2ff 100644 --- a/runtime/plugin/nvim_gui_shim.vim +++ b/runtime/plugin/nvim_gui_shim.vim @@ -5,10 +5,12 @@ 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', a:args[0]), 'v'] + return [rpcrequest(1, 'Gui', 'Clipboard', 'Get', a:args[0]), s:LastRegType] elseif a:method == 'set' + let s:LastRegType = a:args[1] call rpcnotify(1, 'Gui', 'Clipboard', 'Set', a:args[2], join(a:args[0], ' ')) endif endfunction