From 4aa2858b2b69e22b9769df48db5bec1427fade58 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Mon, 22 May 2023 18:05:08 +0200 Subject: [PATCH] Transfer focus to root view only if previously-focused view was dropped --- crates/gpui/src/app.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index bc89503459..0fafe76942 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -1749,11 +1749,11 @@ impl AppContext { } } - // When the previously-focused view isn't rendered and + // When the previously-focused view has been dropped and // there isn't any pending focus, focus the root view. let root_view_id = cx.window.root_view().id(); if focused_view_id != root_view_id - && !cx.window.parents.contains_key(&focused_view_id) + && !cx.views.contains_key(&(window_id, focused_view_id)) && !focus_effects.contains_key(&window_id) { focus_effects.insert( @@ -1942,12 +1942,12 @@ impl AppContext { fn handle_focus_effect(&mut self, effect: FocusEffect) { let window_id = effect.window_id(); self.update_window(window_id, |cx| { - // Ensure the newly-focused view has been rendered, otherwise focus + // Ensure the newly-focused view still exists, otherwise focus // the root view instead. let focused_id = match effect { FocusEffect::View { view_id, .. } => { if let Some(view_id) = view_id { - if cx.window.parents.contains_key(&view_id) { + if cx.views.contains_key(&(window_id, view_id)) { Some(view_id) } else { Some(cx.root_view().id())