Skip to content

Commit

Permalink
Return an empty measurement instead of panicking (#15269)
Browse files Browse the repository at this point in the history
Follow-up of #15256

Returns zero size for no items to render.

Incorrect worktree state made the uniform list to have 0 items to
render, so
```Rust
let mut items = (self.render_items)(item_ix..item_ix + 1, cx);
let mut item_to_measure = items.pop().unwrap();
```
panicked as the first line returned an empty array despite a
single-element range provided.


Release Notes:

- N/A
  • Loading branch information
SomeoneToIgnore authored Jul 26, 2024
1 parent 7aa6f47 commit e830865
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion crates/gpui/src/elements/uniform_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,9 @@ impl UniformList {

let item_ix = cmp::min(self.item_to_measure_index, self.item_count - 1);
let mut items = (self.render_items)(item_ix..item_ix + 1, cx);
let mut item_to_measure = items.pop().unwrap();
let Some(mut item_to_measure) = items.pop() else {
return Size::default();
};
let available_space = size(
list_width.map_or(AvailableSpace::MinContent, |width| {
AvailableSpace::Definite(width)
Expand Down

0 comments on commit e830865

Please sign in to comment.