multi_buffer: Fix editor::ExpandExcerpts failing when cursor is at excerpt start (#42324)
The bug is easily verified by: 1. open any multi-buffer 2. place the cursor at the beginning of an excerpt 3. run the editor::ExpandExcerpts / editor: expand excerpts action 4. The excerpt is not expanded Since the `buffer_ids_for_range` function basically did the same and had even been changed the same way earlier I DRYed these functions as well. Note: I'm a rust novice, so keep an extra eye on rust technicalities when reviewing :) --- Release Notes: - Fix editor: expand excerpts failing when cursor is at excerpt start --------- Co-authored-by: Lukas Wirth <me@lukaswirth.dev>
This commit is contained in:
co-authored by
Lukas Wirth
parent
9122dd2d70
commit
0e2041dd41
@@ -3616,27 +3616,10 @@ impl MultiBufferSnapshot {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn excerpt_ids_for_range<T: ToOffset>(
|
||||
fn excerpts_for_range<T: ToOffset>(
|
||||
&self,
|
||||
range: Range<T>,
|
||||
) -> impl Iterator<Item = ExcerptId> + '_ {
|
||||
let range = range.start.to_offset(self)..range.end.to_offset(self);
|
||||
let mut cursor = self.cursor::<MultiBufferOffset, BufferOffset>();
|
||||
cursor.seek(&range.start);
|
||||
std::iter::from_fn(move || {
|
||||
let region = cursor.region()?;
|
||||
if region.range.start >= range.end {
|
||||
return None;
|
||||
}
|
||||
cursor.next_excerpt();
|
||||
Some(region.excerpt.id)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn buffer_ids_for_range<T: ToOffset>(
|
||||
&self,
|
||||
range: Range<T>,
|
||||
) -> impl Iterator<Item = BufferId> + '_ {
|
||||
) -> impl Iterator<Item = &Excerpt> + '_ {
|
||||
let range = range.start.to_offset(self)..range.end.to_offset(self);
|
||||
let mut cursor = self.cursor::<MultiBufferOffset, BufferOffset>();
|
||||
cursor.seek(&range.start);
|
||||
@@ -3648,10 +3631,25 @@ impl MultiBufferSnapshot {
|
||||
return None;
|
||||
}
|
||||
cursor.next_excerpt();
|
||||
Some(region.excerpt.buffer_id)
|
||||
Some(region.excerpt)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn excerpt_ids_for_range<T: ToOffset>(
|
||||
&self,
|
||||
range: Range<T>,
|
||||
) -> impl Iterator<Item = ExcerptId> + '_ {
|
||||
self.excerpts_for_range(range).map(|excerpt| excerpt.id)
|
||||
}
|
||||
|
||||
pub fn buffer_ids_for_range<T: ToOffset>(
|
||||
&self,
|
||||
range: Range<T>,
|
||||
) -> impl Iterator<Item = BufferId> + '_ {
|
||||
self.excerpts_for_range(range)
|
||||
.map(|excerpt| excerpt.buffer_id)
|
||||
}
|
||||
|
||||
pub fn ranges_to_buffer_ranges<T: ToOffset>(
|
||||
&self,
|
||||
ranges: impl Iterator<Item = Range<T>>,
|
||||
|
||||
Reference in New Issue
Block a user