diff --git a/gpui/src/app.rs b/gpui/src/app.rs index 702fc952a721a0fc4078d20183927d8163bf383e..413c838fdad66d9aa7aec7728e3d2d238cac950c 100644 --- a/gpui/src/app.rs +++ b/gpui/src/app.rs @@ -313,8 +313,11 @@ impl TestAppContext { pub fn update T>(&mut self, callback: F) -> T { let mut state = self.0.borrow_mut(); - state.pending_flushes += 1; + // Don't increment pending flushes in order to effects to be flushed before the callback + // completes, which is helpful in tests. let result = callback(&mut *state); + // Flush effects after the callback just in case there are any. This can happen in edge + // cases such as the closure dropping handles. state.flush_effects(); result } @@ -895,7 +898,7 @@ impl MutableAppContext { } fn flush_effects(&mut self) { - self.pending_flushes -= 1; + self.pending_flushes = self.pending_flushes.saturating_sub(1); if !self.flushing_effects && self.pending_flushes == 0 { self.flushing_effects = true; diff --git a/zed/src/workspace/workspace_view.rs b/zed/src/workspace/workspace_view.rs index aece490d376eabe1a79c2ff65089a32269220c35..6a9b3ca320618839f6cdc67899cf05ac8bd3d707 100644 --- a/zed/src/workspace/workspace_view.rs +++ b/zed/src/workspace/workspace_view.rs @@ -515,13 +515,11 @@ mod tests { ); ctx.dispatch_action(window_id, vec![pane_2.id()], "pane:close_active_item", ()); - }); - app.read(|ctx| { let w = workspace_view.read(ctx); assert_eq!(w.panes.len(), 1); assert_eq!(w.active_pane(), &pane_1); - }) + }); }); } }