better special casing of resize and enable closing via x button

macos-click-through
Keith Simmons 5 years ago
parent 3efb6879dc
commit 4690623ec6

@ -37,7 +37,19 @@ fn create_nvim_command() -> Command {
cmd cmd
} }
pub async fn start_process(editor: Arc<Mutex<Editor>>, mut receiver: UnboundedReceiver<UiCommand>, grid_dimensions: (u64, u64)) { async fn drain(receiver: &mut UnboundedReceiver<UiCommand>) -> Option<Vec<UiCommand>> {
if let Some(ui_command) = receiver.recv().await {
let mut results = vec![ui_command];
while let Ok(ui_command) = receiver.try_recv() {
results.push(ui_command);
}
Some(results)
} else {
None
}
}
async fn start_process(editor: Arc<Mutex<Editor>>, mut receiver: UnboundedReceiver<UiCommand>, grid_dimensions: (u64, u64)) {
let (width, height) = grid_dimensions; let (width, height) = grid_dimensions;
let (mut nvim, io_handler, _) = create::new_child_cmd(&mut create_nvim_command(), NeovimHandler(editor)).await let (mut nvim, io_handler, _) = create::new_child_cmd(&mut create_nvim_command(), NeovimHandler(editor)).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");
@ -61,21 +73,19 @@ pub async fn start_process(editor: Arc<Mutex<Editor>>, mut receiver: UnboundedRe
let nvim = Arc::new(nvim); let nvim = Arc::new(nvim);
loop { loop {
let mut commands = Vec::new(); if let Some(commands) = drain(&mut receiver).await {
let mut resize_command = None; let (resize_list, other_commands): (Vec<UiCommand>, Vec<UiCommand>) = commands
while let Ok(ui_command) = receiver.try_recv() { .into_iter()
if let UiCommand::Resize { .. } = ui_command { .partition(|command| command.is_resize());
resize_command = Some(ui_command); if let Some(resize_command) = resize_list.into_iter().last() {
} else { resize_command.execute(&nvim).await;
commands.push(ui_command);
} }
}
if let Some(resize_command) = resize_command {
commands.push(resize_command);
}
for ui_command in commands.into_iter() { for ui_command in other_commands.into_iter() {
ui_command.execute(&nvim).await; ui_command.execute(&nvim).await;
}
} else {
break;
} }
} }
} }

@ -34,4 +34,11 @@ impl UiCommand {
.expect("Mouse Drag Failed") .expect("Mouse Drag Failed")
} }
} }
pub fn is_resize(&self) -> bool {
match self {
UiCommand::Resize { .. } => true,
_ => false
}
}
} }

Loading…
Cancel
Save