This commit is contained in:
daa 2018-01-08 10:52:47 +03:00
commit 3985f215ce
3 changed files with 23 additions and 9 deletions

View File

@ -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

View File

@ -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::<Vec<Value>>()))

View File

@ -59,7 +59,8 @@ pub struct State {
cursor: Option<Cursor>,
popup_menu: RefCell<PopupMenu>,
settings: Rc<RefCell<Settings>>,
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) {