Skip to content

Commit

Permalink
fix(core): state order and handling of new trees
Browse files Browse the repository at this point in the history
  • Loading branch information
wash2 committed Jul 5, 2024
1 parent 4c609e7 commit 5d0e029
Showing 1 changed file with 8 additions and 33 deletions.
41 changes: 8 additions & 33 deletions core/src/widget/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl Tree {
let state = mem::replace(&mut tree.state, State::None);
let children_count = tree.children.len();
let children =
tree.children.iter_mut().rev().enumerate().map(|(i, c)| {
tree.children.iter_mut().enumerate().rev().map(|(i, c)| {
if matches!(c.id, Some(Id(Internal::Custom(_, _)))) {
(c, None)
} else {
Expand Down Expand Up @@ -167,37 +167,8 @@ impl Tree {
let mut needs_reset = false;
let tag_match = self.tag == borrowed.tag();
if let Some(Id(Internal::Custom(_, n))) = borrowed.id() {
if let Some((mut state, children)) = NAMED
.with(|named| named.borrow_mut().remove(&n))
.or_else(|| {
//check self.id
if let Some(Id(Internal::Custom(_, ref name))) = self.id {
if name == &n {
Some((
mem::replace(&mut self.state, State::None),
self.children
.iter_mut()
.map(|s| {
// take the data
mem::replace(
s,
Tree {
id: s.id.clone(),
tag: s.tag,
..Tree::empty()
},
)
})
.enumerate()
.collect(),
))
} else {
None
}
} else {
None
}
})
if let Some((mut state, children)) =
NAMED.with(|named| named.borrow_mut().remove(&n))
{
std::mem::swap(&mut self.state, &mut state);
let widget_children = borrowed.children();
Expand Down Expand Up @@ -350,7 +321,11 @@ impl Tree {
}

for (new_tree, i) in new_trees {
self.children.insert(i, new_tree);
if self.children.len() > i {
self.children[i] = new_tree;
} else {
self.children.push(new_tree);
}
}
}
}
Expand Down

0 comments on commit 5d0e029

Please sign in to comment.