Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

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

Cole Miller7691cf341c59
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs
index a4a8a5e02ba..f70693a8d67 100644
--- a/crates/editor/src/editor.rs
+++ b/crates/editor/src/editor.rs
@@ -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()
}));
},
);