fix redraw event order

macos-click-through
Keith Simmons 5 years ago
parent 4079f218b3
commit 5a8d24b77c

@ -4,13 +4,38 @@ use rmpv::Value;
use nvim_rs::{Neovim, Handler, compat::tokio::Compat}; use nvim_rs::{Neovim, Handler, compat::tokio::Compat};
use async_trait::async_trait; use async_trait::async_trait;
use tokio::process::ChildStdin; use tokio::process::ChildStdin;
use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender};
use crate::error_handling::ResultPanicExplanation; use crate::error_handling::ResultPanicExplanation;
use crate::editor::{EDITOR, Editor}; use crate::editor::{EDITOR, Editor};
use super::events::parse_neovim_event; use super::events::{RedrawEvent, parse_neovim_event};
#[derive(Clone)] #[derive(Clone)]
pub struct NeovimHandler { } pub struct NeovimHandler {
sender: UnboundedSender<RedrawEvent>
}
impl NeovimHandler {
pub fn new() -> NeovimHandler {
let (sender, mut receiver) = unbounded_channel::<RedrawEvent>();
tokio::spawn(async move {
while let Some(event) = receiver.recv().await {
let mut editor = EDITOR.lock().unwrap();
editor.handle_redraw_event(event);
}
});
NeovimHandler {
sender
}
}
pub fn handle_redraw_event(&self, event: RedrawEvent) {
self.sender.send(event);
}
}
#[async_trait] #[async_trait]
impl Handler for NeovimHandler { impl Handler for NeovimHandler {
@ -20,8 +45,7 @@ impl Handler for NeovimHandler {
let parsed_events = parse_neovim_event(event_name, arguments) let parsed_events = parse_neovim_event(event_name, arguments)
.unwrap_or_explained_panic("Could not parse event", "Could not parse event from neovim"); .unwrap_or_explained_panic("Could not parse event", "Could not parse event from neovim");
for event in parsed_events { for event in parsed_events {
let mut editor = EDITOR.lock().unwrap(); self.handle_redraw_event(event);
editor.handle_redraw_event(event);
} }
} }
} }

@ -56,7 +56,7 @@ async fn drain(receiver: &mut UnboundedReceiver<UiCommand>) -> Option<Vec<UiComm
async fn start_process(mut receiver: UnboundedReceiver<UiCommand>) { async fn start_process(mut receiver: UnboundedReceiver<UiCommand>) {
let (width, height) = INITIAL_DIMENSIONS; let (width, height) = INITIAL_DIMENSIONS;
let (mut nvim, io_handler, _) = create::new_child_cmd(&mut create_nvim_command(), NeovimHandler { }).await let (mut nvim, io_handler, _) = create::new_child_cmd(&mut create_nvim_command(), NeovimHandler::new()).await
.unwrap_or_explained_panic("Could not create nvim process", "Could not locate or start the neovim process"); .unwrap_or_explained_panic("Could not create nvim process", "Could not locate or start the neovim process");
tokio::spawn(async move { tokio::spawn(async move {

Loading…
Cancel
Save