Fix @children next to Timer or PopupWindow

Fixes #7887
This commit is contained in:
Olivier Goffart 2025-03-21 14:49:25 +01:00
parent ed47d1e70a
commit 70c7fd1b49
4 changed files with 110 additions and 16 deletions

View file

@ -90,14 +90,20 @@ fn lower_popup_window(
}
// Remove the popup_window_element from its parent
let old_size = parent_element.borrow().children.len();
parent_element.borrow_mut().children.retain(|child| !Rc::ptr_eq(child, popup_window_element));
debug_assert_eq!(
parent_element.borrow().children.len() + 1,
old_size,
"Exactly one child must be removed (the popup itself)"
);
parent_element.borrow_mut().has_popup_child = true;
let mut parent_element_borrowed = parent_element.borrow_mut();
let index = parent_element_borrowed
.children
.iter()
.position(|child| Rc::ptr_eq(child, popup_window_element))
.expect("PopupWindow must be a child of its parent");
parent_element_borrowed.children.remove(index);
parent_element_borrowed.has_popup_child = true;
drop(parent_element_borrowed);
if let Some((p, idx, _)) = &mut *parent_component.child_insertion_point.borrow_mut() {
if Rc::ptr_eq(p, parent_element) && *idx > index {
*idx -= 1;
}
}
if matches!(popup_window_element.borrow().base_type, ElementType::Builtin(_)) {
popup_window_element.borrow_mut().base_type = window_type.clone();

View file

@ -52,14 +52,20 @@ fn lower_timer(
}
// Remove the timer_element from its parent
let old_size = parent_element.borrow().children.len();
parent_element.borrow_mut().children.retain(|child| !Rc::ptr_eq(child, timer_element));
debug_assert_eq!(
parent_element.borrow().children.len() + 1,
old_size,
"Exactly one child must be removed (the timer itself)"
);
parent_component.optimized_elements.borrow_mut().push(timer_element.clone());
let mut parent_element_borrowed = parent_element.borrow_mut();
let index = parent_element_borrowed
.children
.iter()
.position(|child| Rc::ptr_eq(child, timer_element))
.expect("Timer must be a child of its parent");
let removed = parent_element_borrowed.children.remove(index);
parent_component.optimized_elements.borrow_mut().push(removed);
drop(parent_element_borrowed);
if let Some((p, idx, _)) = &mut *parent_component.child_insertion_point.borrow_mut() {
if Rc::ptr_eq(p, parent_element) && *idx > index {
*idx -= 1;
}
}
parent_component.timers.borrow_mut().push(Timer {
interval: NamedReference::new(timer_element, SmolStr::new_static("interval")),