Don't assume that the excerpt can be found (#27395)

Release Notes:

- Fix (rare) panic in the project diff view
This commit is contained in:
Conrad Irwin 2025-03-24 16:12:26 -06:00 committed by GitHub
parent 10c04afc81
commit 46d67a33c7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1645,7 +1645,11 @@ impl MultiBuffer {
}; };
let locator = snapshot.excerpt_locator_for_id(*existing); let locator = snapshot.excerpt_locator_for_id(*existing);
excerpts_cursor.seek_forward(&Some(locator), Bias::Left, &()); excerpts_cursor.seek_forward(&Some(locator), Bias::Left, &());
let existing_excerpt = excerpts_cursor.item().unwrap(); let Some(existing_excerpt) = excerpts_cursor.item() else {
to_remove.push(existing_iter.next().unwrap());
to_insert.push(new_iter.next().unwrap());
continue;
};
if existing_excerpt.buffer_id != buffer_snapshot.remote_id() { if existing_excerpt.buffer_id != buffer_snapshot.remote_id() {
to_remove.push(existing_iter.next().unwrap()); to_remove.push(existing_iter.next().unwrap());
to_insert.push(new_iter.next().unwrap()); to_insert.push(new_iter.next().unwrap());