Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Better fix for multiple focuses in one frame
Conrad Irwin2625051f75ad
diff --git a/crates/gpui2/src/app.rs b/crates/gpui2/src/app.rsindex 356cf1b76bf..61c6195d903 100644--- a/crates/gpui2/src/app.rs+++ b/crates/gpui2/src/app.rs@@ -641,14 +641,19 @@ impl AppContext {// The window might change focus multiple times in an effect cycle.// We only honor effects for the most recently focused handle.if cx.window.focus == focused {+ // if someone calls focus multiple times in one frame with the same handle+ // the first apply_focus_changed_effect will have taken the last blur already+ // and run the rest of this, so we can return.+ let Some(last_blur) = cx.window.last_blur.take() else {+ return;+ };+let focused = focused.map(|id| FocusHandle::for_id(id, &cx.window.focus_handles).unwrap());- let blurred = cx- .window- .last_blur- .take()- .unwrap()- .and_then(|id| FocusHandle::for_id(id, &cx.window.focus_handles));++ let blurred =+ last_blur.and_then(|id| FocusHandle::for_id(id, &cx.window.focus_handles));+let focus_changed = focused.is_some() || blurred.is_some();let event = FocusEvent { focused, blurred };diff --git a/crates/gpui2/src/window.rs b/crates/gpui2/src/window.rsindex f574d7eb5f5..11878c15fa2 100644--- a/crates/gpui2/src/window.rs+++ b/crates/gpui2/src/window.rs@@ -389,10 +389,6 @@ impl<'a> WindowContext<'a> {pub fn focus(&mut self, handle: &FocusHandle) {let focus_id = handle.id;- if self.window.focus == Some(focus_id) {- return;- }-if self.window.last_blur.is_none() {self.window.last_blur = Some(self.window.focus);}