Skip to content

Commit

Permalink
Fix panic when drag-dropping tiles to the last place
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Jun 28, 2023
1 parent 0127ad5 commit f958d8a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/container/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ impl Grid {
}
}

/// Returns the child already at the given index, if any.
#[must_use]
pub fn replace_at(&mut self, index: usize, child: TileId) -> Option<TileId> {
if let Some(slot) = self.children.get_mut(index) {
Expand Down
6 changes: 4 additions & 2 deletions src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,13 @@ impl<Pane> Tree<Pane> {
Tile::Pane(_) => unreachable!(),
Tile::Container(container) => match container {
Container::Tabs(tabs) => {
tabs.children.insert(adjusted_index, moved_tile_id);
let insertion_index = adjusted_index.min(tabs.children.len());
tabs.children.insert(insertion_index, moved_tile_id);
tabs.active = Some(moved_tile_id);
}
Container::Linear(linear) => {
linear.children.insert(adjusted_index, moved_tile_id);
let insertion_index = adjusted_index.min(linear.children.len());
linear.children.insert(insertion_index, moved_tile_id);
}
Container::Grid(grid) => {
// the grid allow holes in its children list, so don't use `adjusted_index`
Expand Down

0 comments on commit f958d8a

Please sign in to comment.