Fix :q panic

This commit is contained in:
daa84 2017-11-13 12:15:13 +03:00
parent 54fd5775e9
commit 9f17a8bb09
2 changed files with 19 additions and 8 deletions

View File

@ -69,9 +69,7 @@ impl NeovimClientAsync {
impl Clone for NeovimClientAsync {
fn clone(&self) -> Self {
NeovimClientAsync {
nvim: self.nvim.clone()
}
NeovimClientAsync { nvim: self.nvim.clone() }
}
}
@ -90,11 +88,17 @@ impl NeovimClient {
}
}
pub fn clear(&self) {
let mut nvim = self.nvim.borrow_mut();
if nvim.is_some() {
nvim.take();
} else {
self.nvim_async.nvim.lock().unwrap().take();
}
}
pub fn async_to_sync(&self) {
let mut lock = self.nvim_async
.nvim
.lock()
.unwrap();
let mut lock = self.nvim_async.nvim.lock().unwrap();
let nvim = lock.take().unwrap();
*self.nvim.borrow_mut() = Some(nvim);
}

View File

@ -783,7 +783,14 @@ fn init_nvim_async(
thread::spawn(move || {
guard.join().expect("Can't join dispatch thread");
idle_cb_call!(state_ref.detach_cb());
glib::idle_add(move || {
state_ref.borrow().nvim.clear();
if let Some(ref cb) = state_ref.borrow().detach_cb {
(&mut *cb.borrow_mut())();
}
glib::Continue(false)
});
});
// attach ui