From 35e0eaaae227383de9eff3ec52c8896bc7dd7060 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 6 May 2021 16:30:10 -0600 Subject: [PATCH] Refocus root view if focused view is removed Co-Authored-By: Max Brunsfeld --- gpui/src/app.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/gpui/src/app.rs b/gpui/src/app.rs index c036f629f930d7f96f9c10980affd2f1e0fc96e1..a5758903fc9a96e719b1683b228c27ced066a7df 100644 --- a/gpui/src/app.rs +++ b/gpui/src/app.rs @@ -884,12 +884,21 @@ impl MutableAppContext { self.model_observations.remove(&view_id); self.async_observations.remove(&view_id); self.ctx.views.remove(&(window_id, view_id)); - if let Some(window) = self.ctx.windows.get_mut(&window_id) { + let change_focus_to = self.ctx.windows.get_mut(&window_id).and_then(|window| { window .invalidation .get_or_insert_with(Default::default) .removed .push(view_id); + if window.focused_view_id == view_id { + Some(window.root_view.id()) + } else { + None + } + }); + + if let Some(view_id) = change_focus_to { + self.focus(window_id, view_id); } }