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.

multi_buffer: Fix a panic when expanding an excerpt with the cursor at the end (#17955)

Marshall Bowers5cdca6d8dd8c
diff --git a/crates/multi_buffer/src/multi_buffer.rs b/crates/multi_buffer/src/multi_buffer.rs
index f7172ccf08d..5b6eddd5b16 100644
--- a/crates/multi_buffer/src/multi_buffer.rs
+++ b/crates/multi_buffer/src/multi_buffer.rs
@@ -3790,7 +3790,7 @@ impl MultiBufferSnapshot {
}
}
- // Returns the locators referenced by the given excerpt ids, sorted by locator.
+ /// Returns the locators referenced by the given excerpt IDs, sorted by locator.
fn excerpt_locators_for_ids(
&self,
ids: impl IntoIterator<Item = ExcerptId>,
@@ -3801,13 +3801,17 @@ impl MultiBufferSnapshot {
while sorted_ids.last() == Some(&ExcerptId::max()) {
sorted_ids.pop();
- locators.push(Locator::max());
+ if let Some(mapping) = self.excerpt_ids.last() {
+ locators.push(mapping.locator.clone());
+ }
}
let mut sorted_ids = sorted_ids.into_iter().dedup().peekable();
if sorted_ids.peek() == Some(&ExcerptId::min()) {
sorted_ids.next();
- locators.push(Locator::min());
+ if let Some(mapping) = self.excerpt_ids.first() {
+ locators.push(mapping.locator.clone());
+ }
}
let mut cursor = self.excerpt_ids.cursor::<ExcerptId>();