Skip to content

Commit

Permalink
fix: ensure target index is within bounds of parent's children on attach
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-berger committed Jul 31, 2024
1 parent 9c6b27c commit 28d0319
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/wm/src/containers/commands/attach_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ pub fn attach_container(
bail!("Cannot attach an already attached container.");
}

// Insert the child at the specified index.
if let Some(target_index) = target_index {
// Ensure target index is within the bounds of the parent's children.
let target_index = target_index.clamp(0, target_parent.child_count());

// Insert the child at the specified index.
target_parent
.borrow_children_mut()
.insert(target_index, child.clone());
Expand Down

0 comments on commit 28d0319

Please sign in to comment.