Remove WindowContext::is_child_focused
This commit is contained in:
parent
67a3891f15
commit
f6f18be9c3
4 changed files with 12 additions and 26 deletions
|
@ -5360,10 +5360,6 @@ mod tests {
|
|||
cx.focus(&view_2);
|
||||
});
|
||||
|
||||
cx.read_window(window_id, |cx| {
|
||||
assert!(cx.is_child_focused(&view_1));
|
||||
assert!(!cx.is_child_focused(&view_2));
|
||||
});
|
||||
assert_eq!(
|
||||
mem::take(&mut *view_events.lock()),
|
||||
["view 1 blurred", "view 2 focused"],
|
||||
|
@ -5377,10 +5373,6 @@ mod tests {
|
|||
);
|
||||
|
||||
view_1.update(cx, |_, cx| cx.focus(&view_1));
|
||||
cx.read_window(window_id, |cx| {
|
||||
assert!(!cx.is_child_focused(&view_1));
|
||||
assert!(!cx.is_child_focused(&view_2));
|
||||
});
|
||||
assert_eq!(
|
||||
mem::take(&mut *view_events.lock()),
|
||||
["view 2 blurred", "view 1 focused"],
|
||||
|
|
|
@ -1085,16 +1085,6 @@ impl<'a> WindowContext<'a> {
|
|||
self.window.focused_view_id
|
||||
}
|
||||
|
||||
pub fn is_child_focused(&self, view: &AnyViewHandle) -> bool {
|
||||
if let Some(focused_view_id) = self.focused_view_id() {
|
||||
self.ancestors(focused_view_id)
|
||||
.skip(1) // Skip self id
|
||||
.any(|parent| parent == view.view_id)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn window_bounds(&self) -> WindowBounds {
|
||||
self.window.platform_window.bounds()
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue