diff --git a/packages/native-core/src/utils.rs b/packages/native-core/src/utils.rs index efd2a1d3b..cd18df01e 100644 --- a/packages/native-core/src/utils.rs +++ b/packages/native-core/src/utils.rs @@ -78,6 +78,7 @@ impl PersistantElementIter { } }) .collect(); + // if any element is removed in the chain, remove it and its children from the stack if let Some(r) = self .stack .iter() @@ -165,6 +166,7 @@ impl PersistantElementIter { /// get the previous element pub fn prev(&mut self, rdom: &RealDom) -> ElementProduced { + // recursively add the last child element to the stack fn push_back( stack: &mut smallvec::SmallVec<[(ElementId, NodePosition); 5]>, new_node: ElementId, diff --git a/packages/tui/src/focus.rs b/packages/tui/src/focus.rs index 2ea83a897..fa2e1dd97 100644 --- a/packages/tui/src/focus.rs +++ b/packages/tui/src/focus.rs @@ -120,11 +120,10 @@ impl FocusState { return false; } } + // the id that started focused to track when a loop has happened let mut loop_marker_id = self.last_focused_id; let focus_level = &mut self.focus_level; let mut next_focus = None; - let starting_focus_level = *focus_level; - let mut focus_level_changed = false; loop { let new = if forward { @@ -175,9 +174,6 @@ impl FocusState { if let Some(level) = closest_level { *focus_level = level; - if *focus_level != starting_focus_level { - focus_level_changed = true; - } } else { if forward { *focus_level = FocusLevel::Unfocusable; @@ -185,11 +181,6 @@ impl FocusState { *focus_level = FocusLevel::Focusable; } } - - // if the focus level looped, we are done - if *focus_level == starting_focus_level && focus_level_changed { - break; - } } // once we have looked at all the elements exit the loop @@ -209,28 +200,21 @@ impl FocusState { }; if after_previous_focused && current_level.focusable() { if current_level == *focus_level { - next_focus = Some((new_id, current_level)); + next_focus = Some(new_id); break; } } } - if let Some((id, order)) = next_focus { - if order.focusable() { - rdom[id].state.focused = true; - if let Some(old) = self.last_focused_id.replace(id) { - rdom[old].state.focused = false; - } - // reset the position to the currently focused element - while if forward { - self.focus_iter.next(&rdom).id() - } else { - self.focus_iter.prev(&rdom).id() - } != id - {} - self.dirty = true; - return true; + if let Some(id) = next_focus { + rdom[id].state.focused = true; + if let Some(old) = self.last_focused_id.replace(id) { + rdom[old].state.focused = false; } + // reset the position to the currently focused element + while self.focus_iter.next(&rdom).id() != id {} + self.dirty = true; + return true; } false