better resize handling

macos-click-through
Keith Simmons 5 years ago
parent e0acbd0b9f
commit c96a44a9e1

@ -103,12 +103,9 @@ async fn start_nvim(editor: Arc<Mutex<Editor>>, mut receiver: UnboundedReceiver<
commands.push(resize_command);
}
let nvim = nvim.clone();
tokio::spawn(async move {
for ui_command in commands.into_iter() {
ui_command.execute(&nvim).await;
}
});
}
}

@ -1,3 +1,5 @@
use std::sync::Arc;
use nvim_rs::Neovim;
use nvim_rs::compat::tokio::Compat;
use tokio::process::ChildStdin;
@ -12,23 +14,23 @@ pub enum UiCommand {
}
impl UiCommand {
pub async fn execute(&self, nvim: &Neovim<Compat<ChildStdin>>) {
pub async fn execute(self, nvim: &Neovim<Compat<ChildStdin>>) {
match self {
UiCommand::Resize { width, height } =>
nvim.ui_try_resize(*width.max(&10), *height.max(&3)).await
nvim.ui_try_resize(width.max(10), height.max(3)).await
.expect("Resize failed"),
UiCommand::Keyboard(input_command) => {
nvim.input(&input_command).await
.expect("Input failed");
},
UiCommand::MouseButton { action, position: (grid_x, grid_y) } =>
nvim.input_mouse("left", action, "", 0, *grid_x, *grid_y).await
nvim.input_mouse("left", &action, "", 0, grid_x, grid_y).await
.expect("Mouse Input Failed"),
UiCommand::Scroll { direction, position: (grid_x, grid_y) } =>
nvim.input_mouse("wheel", direction, "", 0, *grid_x, *grid_y).await
nvim.input_mouse("wheel", &direction, "", 0, grid_x, grid_y).await
.expect("Mouse Scroll Failed"),
UiCommand::Drag(grid_x, grid_y) =>
nvim.input_mouse("left", "drag", "", 0, *grid_x, *grid_y).await
nvim.input_mouse("left", "drag", "", 0, grid_x, grid_y).await
.expect("Mouse Drag Failed")
}
}

Loading…
Cancel
Save