Notify old/new ancestors of the focused view when they change
This commit is contained in:
parent
981129ef8e
commit
747fbfadeb
2 changed files with 49 additions and 6 deletions
|
@ -1694,12 +1694,54 @@ impl AppContext {
|
|||
if let Some(invalidation) = invalidation {
|
||||
let appearance = cx.window.platform_window.appearance();
|
||||
cx.invalidate(invalidation, appearance);
|
||||
if cx.layout(refreshing).log_err().is_some() {
|
||||
if let Some(old_parents) = cx.layout(refreshing).log_err() {
|
||||
updated_windows.insert(window_id);
|
||||
|
||||
// When the previously-focused view isn't rendered and
|
||||
// there isn't any pending focus, focus the root view.
|
||||
if let Some(focused_view_id) = cx.focused_view_id() {
|
||||
let old_ancestors = std::iter::successors(
|
||||
Some(focused_view_id),
|
||||
|&view_id| old_parents.get(&view_id).copied(),
|
||||
)
|
||||
.collect::<HashSet<_>>();
|
||||
let new_ancestors =
|
||||
cx.ancestors(focused_view_id).collect::<HashSet<_>>();
|
||||
|
||||
// Notify the old ancestors of the focused view when they don't contain it anymore.
|
||||
for old_ancestor in old_ancestors.iter().copied() {
|
||||
if !new_ancestors.contains(&old_ancestor) {
|
||||
if let Some(mut view) =
|
||||
cx.views.remove(&(window_id, old_ancestor))
|
||||
{
|
||||
view.focus_out(
|
||||
focused_view_id,
|
||||
cx,
|
||||
old_ancestor,
|
||||
);
|
||||
cx.views
|
||||
.insert((window_id, old_ancestor), view);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Notify the new ancestors of the focused view if they contain it now.
|
||||
for new_ancestor in new_ancestors.iter().copied() {
|
||||
if !old_ancestors.contains(&new_ancestor) {
|
||||
if let Some(mut view) =
|
||||
cx.views.remove(&(window_id, new_ancestor))
|
||||
{
|
||||
view.focus_in(
|
||||
focused_view_id,
|
||||
cx,
|
||||
new_ancestor,
|
||||
);
|
||||
cx.views
|
||||
.insert((window_id, new_ancestor), view);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// When the previously-focused view isn't rendered 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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue