Remove WindowContext::is_child_focused

This commit is contained in:
Antonio Scandurra 2023-05-04 09:49:38 +02:00
parent 67a3891f15
commit f6f18be9c3
4 changed files with 12 additions and 26 deletions

View file

@ -151,6 +151,7 @@ pub struct Pane {
docked: Option<DockAnchor>,
_background_actions: BackgroundActions,
workspace: WeakViewHandle<Workspace>,
has_focus: bool,
}
pub struct ItemNavHistory {
@ -258,6 +259,7 @@ impl Pane {
docked,
_background_actions: background_actions,
workspace,
has_focus: false,
}
}
@ -274,6 +276,10 @@ impl Pane {
cx.notify();
}
pub fn has_focus(&self) -> bool {
self.has_focus
}
pub fn set_docked(&mut self, docked: Option<DockAnchor>, cx: &mut ViewContext<Self>) {
self.docked = docked;
cx.notify();
@ -1798,7 +1804,7 @@ impl View for Pane {
}
fn focus_in(&mut self, focused: AnyViewHandle, cx: &mut ViewContext<Self>) {
cx.emit(Event::Focus);
self.has_focus = true;
self.toolbar.update(cx, |toolbar, cx| {
toolbar.pane_focus_update(true, cx);
});
@ -1824,9 +1830,12 @@ impl View for Pane {
.insert(active_item.id(), focused.downgrade());
}
}
cx.emit(Event::Focus);
}
fn focus_out(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
self.has_focus = false;
self.toolbar.update(cx, |toolbar, cx| {
toolbar.pane_focus_update(false, cx);
});

View file

@ -2339,19 +2339,14 @@ impl Workspace {
}
for (pane, item) in items_to_activate {
let active_item_was_focused = pane
.read(cx)
.active_item()
.map(|active_item| cx.is_child_focused(active_item.as_any()))
.unwrap_or_default();
let pane_was_focused = pane.read(cx).has_focus();
if let Some(index) = pane.update(cx, |pane, _| pane.index_for_item(item.as_ref())) {
pane.update(cx, |pane, cx| pane.activate_item(index, false, false, cx));
} else {
Pane::add_item(self, &pane, item.boxed_clone(), false, false, None, cx);
}
if active_item_was_focused {
if pane_was_focused {
pane.update(cx, |pane, cx| pane.focus_active_item(cx));
}
}