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 panic in enclosing bracket ranges (#8870)

Conrad Irwine0c66b30c85c
diff --git a/crates/multi_buffer/src/multi_buffer.rs b/crates/multi_buffer/src/multi_buffer.rs
index 61af2d366c3..60b8af4a532 100644
--- a/crates/multi_buffer/src/multi_buffer.rs
+++ b/crates/multi_buffer/src/multi_buffer.rs
@@ -195,7 +195,7 @@ struct Excerpt {
///
/// Contains methods for getting the [`Buffer`] of the excerpt,
/// as well as mapping offsets to/from buffer and multibuffer coordinates.
-#[derive(Copy, Clone)]
+#[derive(Clone)]
pub struct MultiBufferExcerpt<'a> {
excerpt: &'a Excerpt,
excerpt_offset: usize,
@@ -2963,7 +2963,16 @@ impl MultiBufferSnapshot {
excerpt
.buffer()
.enclosing_bracket_ranges(excerpt.map_range_to_buffer(range))
- .filter(move |(open, close)| excerpt.contains_buffer_range(open.start..close.end)),
+ .filter_map(move |(open, close)| {
+ if excerpt.contains_buffer_range(open.start..close.end) {
+ Some((
+ excerpt.map_range_from_buffer(open),
+ excerpt.map_range_from_buffer(close),
+ ))
+ } else {
+ None
+ }
+ }),
)
}