Skip to content

Commit

Permalink
fix(Tree): check if we're on the last selectable node on NavigationAc…
Browse files Browse the repository at this point in the history
…tion::Down
  • Loading branch information
lautarodragan committed Feb 7, 2025
1 parent 939a812 commit a46faa2
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/components/tree/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,25 +358,29 @@ where
initial_i.with_child(0)
} else {
// Walk next/up/next
let mut dynamic_path = initial_i.clone();
let mut path = initial_i.clone();

loop {
if dynamic_path.is_empty() {
if path.is_empty() {
log::error!("NavigationAction::Down: dynamic_path is empty already! {initial_i:?}");
break initial_i.clone();
};

let last = dynamic_path.last();
dynamic_path = dynamic_path.parent();
let last = path.last();
path = path.parent();

if dynamic_path.is_empty() {
break TreeNodePath::from_vec(vec![(last + 1).min(nodes.len().saturating_sub(1))]);
if path.is_empty() {
if last == nodes.len() - 1 {
break initial_i.clone();
} else {
break TreeNodePath::from_vec(vec![(last + 1).min(nodes.len().saturating_sub(1))]);
}
}

let parent_node = TreeNode::get_node_at_path(&dynamic_path, &nodes).unwrap();
let parent_node = TreeNode::get_node_at_path(&path, &nodes).unwrap();

if parent_node.children.len() > last + 1 {
break dynamic_path.with_child(last + 1);
break path.with_child(last + 1);
}
}
}
Expand Down

0 comments on commit a46faa2

Please sign in to comment.