Fix selections when opening excerpt with an existing buffer that has expanded diff hunks (#44360)

Release Notes:

- N/A
This commit is contained in:
Cole Miller
2025-12-08 06:12:10 +00:00
committed by GitHub
parent 63cc90cd2c
commit 7691cf341c
+11 -2
View File
@@ -22102,14 +22102,23 @@ impl Editor {
None => Autoscroll::newest(),
};
let nav_history = editor.nav_history.take();
let multibuffer_snapshot = editor.buffer().read(cx).snapshot(cx);
let Some((&excerpt_id, _, buffer_snapshot)) =
multibuffer_snapshot.as_singleton()
else {
return;
};
editor.change_selections(
SelectionEffects::scroll(autoscroll),
window,
cx,
|s| {
s.select_ranges(ranges.into_iter().map(|range| {
// we checked that the editor is a singleton editor so the offsets are valid
MultiBufferOffset(range.start.0)..MultiBufferOffset(range.end.0)
let range = buffer_snapshot.anchor_before(range.start)
..buffer_snapshot.anchor_after(range.end);
multibuffer_snapshot
.anchor_range_in_excerpt(excerpt_id, range)
.unwrap()
}));
},
);