From bafa36b8ca1ece2cc98de40f89ef8c0946d473de Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Thu, 2 Jan 2020 20:33:20 -0800 Subject: [PATCH] simplify middle mouse button paste logic Now that we can tell whether the mouse is grabbed, we can safely process the paste in the same way that we use for keyboard initiated pasting. --- src/frontend/gui/termwindow.rs | 63 +++++++++++++--------------------- 1 file changed, 23 insertions(+), 40 deletions(-) diff --git a/src/frontend/gui/termwindow.rs b/src/frontend/gui/termwindow.rs index f5ff6349f..7a8d1459d 100644 --- a/src/frontend/gui/termwindow.rs +++ b/src/frontend/gui/termwindow.rs @@ -373,51 +373,34 @@ impl WindowCallbacks for TermWindow { }; if let WMEK::Press(MousePress::Middle) = event.kind { - // The middle button will typically want to paste the clipboard but - // obtaining the contents is an async operation that requires the - // event loop to pump. - // So we schedule that work and continue with dispatching the middle - // button once we have it. - // want to paste the clipboard, + if !tab.is_mouse_grabbed() { + // Middle mouse button is Paste - let tab_id = tab.tab_id(); - let window_clone = self.window.as_ref().cloned().unwrap(); - let future = self.window.as_ref().unwrap().get_clipboard(); - Connection::get().unwrap().spawn_task(async move { - if let Ok(clip) = future.await { - window_clone.apply(move |myself, context| { - if let Some(myself) = myself.downcast_mut::() { - myself - .clipboard_contents - .lock() - .unwrap() - .replace(clip.clone()); + let tab_id = tab.tab_id(); + let future = self.window.as_ref().unwrap().get_clipboard(); + Connection::get().unwrap().spawn_task(async move { + if let Ok(clip) = future.await { + promise::Future::with_executor(executor(), move || { let mux = Mux::get().unwrap(); if let Some(tab) = mux.get_tab(tab_id) { - tab.mouse_event( - mouse_event, - &mut Host { - writer: &mut *tab.writer(), - context, - }, - ) - .ok(); + tab.trickle_paste(clip)?; } - } - Ok(()) - }); - } - }); - } else { - tab.mouse_event( - mouse_event, - &mut Host { - writer: &mut *tab.writer(), - context, - }, - ) - .ok(); + Ok(()) + }); + } + }); + return; + } } + + tab.mouse_event( + mouse_event, + &mut Host { + writer: &mut *tab.writer(), + context, + }, + ) + .ok(); } match event.kind {