Compare commits

...

1 Commits

Author SHA1 Message Date
Conrad Irwin
1061d99cf2 Wait for pending keystrokes 2025-06-13 13:02:23 -06:00
3 changed files with 23 additions and 1 deletions

View File

@@ -813,6 +813,7 @@ pub struct Window {
pub(crate) pending_input_observers: SubscriberSet<(), AnyObserver>,
prompt: Option<RenderablePromptHandle>,
pub(crate) client_inset: Option<Pixels>,
wait_for_pending_keystroke: Option<oneshot::Receiver<()>>,
#[cfg(any(feature = "inspector", debug_assertions))]
inspector: Option<Entity<Inspector>>,
}
@@ -1092,6 +1093,7 @@ impl Window {
next_frame_callbacks,
next_hitbox_id: HitboxId(0),
next_tooltip_id: TooltipId::default(),
wait_for_pending_keystroke: None,
tooltip_bounds: None,
dirty_views: FxHashSet::default(),
focus_listeners: SubscriberSet::new(),
@@ -1285,6 +1287,22 @@ impl Window {
style
}
/// docs
pub fn finished_handled_keystroke_after(&mut self) -> oneshot::Sender<()> {
let (tx, rx) = oneshot::channel();
self.wait_for_pending_keystroke.replace(rx);
tx
}
/// docs
pub fn wait_until_finished_handling_keystrokes(&mut self) -> oneshot::Receiver<()> {
if let Some(waiter) = self.wait_for_pending_keystroke.take() {
waiter
} else {
oneshot::channel().1
}
}
/// Check if the platform window is maximized
/// On some platforms (namely Windows) this is different than the bounds being the size of the display
pub fn is_maximized(&self) -> bool {

View File

@@ -643,6 +643,7 @@ impl<D: PickerDelegate> Picker<D> {
let delegate_pending_update_matches = self.delegate.update_matches(query, window, cx);
self.matches_updated(window, cx);
let done = window.finished_handled_keystroke_after();
// This struct ensures that we can synchronously drop the task returned by the
// delegate's `update_matches` method and the task that the picker is spawning.
// If we simply capture the delegate's task into the picker's task, when the picker's
@@ -661,6 +662,7 @@ impl<D: PickerDelegate> Picker<D> {
.unwrap()
})?;
delegate_pending_update_matches.await;
drop(done);
this.update_in(cx, |this, window, cx| {
this.matches_updated(window, cx);
})

View File

@@ -2198,7 +2198,9 @@ impl Workspace {
// )
window.draw(cx);
}
})?;
window.wait_until_finished_handling_keystrokes()
})?
.await;
}
*keystrokes.borrow_mut() = Default::default();