Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
workspace: Properly flush effects in `send_keystrokes_impl` (#50486)
Lukas Wirth8f329d1ee330
diff --git a/crates/command_palette/src/command_palette.rs b/crates/command_palette/src/command_palette.rsindex a6fc0193a4b..d13360a7c54 100644--- a/crates/command_palette/src/command_palette.rs+++ b/crates/command_palette/src/command_palette.rs@@ -510,7 +510,7 @@ impl PickerDelegate for CommandPaletteDelegate {.delegate.matches_updated(query, commands, matches, intercept_result, cx)})- .log_err();+ .ok();})}@@ -543,7 +543,7 @@ impl PickerDelegate for CommandPaletteDelegate {fn dismissed(&mut self, _window: &mut Window, cx: &mut Context<Picker<Self>>) {self.command_palette.update(cx, |_, cx| cx.emit(DismissEvent))- .log_err();+ .ok();}fn confirm(&mut self, secondary: bool, window: &mut Window, cx: &mut Context<Picker<Self>>) {diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rsindex cde04d987a0..b62f6b5eb60 100644--- a/crates/workspace/src/workspace.rs+++ b/crates/workspace/src/workspace.rs@@ -14,6 +14,7 @@ mod persistence;pub mod searchable;mod security_modal;pub mod shared_screen;+use db::smol::future::yield_now;pub use shared_screen::SharedScreen;mod status_bar;pub mod tasks;@@ -2820,13 +2821,15 @@ impl Workspace {.spawn(cx, async move |cx| {// limit to 100 keystrokes to avoid infinite recursion.for _ in 0..100 {- let mut state = keystrokes.borrow_mut();- let Some(keystroke) = state.queue.pop_front() else {- state.dispatched.clear();- state.task.take();- return;+ let keystroke = {+ let mut state = keystrokes.borrow_mut();+ let Some(keystroke) = state.queue.pop_front() else {+ state.dispatched.clear();+ state.task.take();+ return;+ };+ keystroke};- drop(state);cx.update(|window, cx| {let focused = window.focused(cx);window.dispatch_keystroke(keystroke.clone(), cx);@@ -2841,6 +2844,10 @@ impl Workspace {}}).ok();++ // Yield between synthetic keystrokes so deferred focus and+ // other effects can settle before dispatching the next key.+ yield_now().await;}*keystrokes.borrow_mut() = Default::default();