Allow buffer search to search deleted hunks (#23632)
Closes #ISSUE Release Notes: - N/A
This commit is contained in:
parent
22afec32cf
commit
1973bf5268
2 changed files with 80 additions and 50 deletions
|
@ -3376,6 +3376,49 @@ impl MultiBufferSnapshot {
|
|||
result
|
||||
}
|
||||
|
||||
pub fn range_to_buffer_ranges_with_deleted_hunks<T: ToOffset>(
|
||||
&self,
|
||||
range: Range<T>,
|
||||
) -> impl Iterator<Item = (&BufferSnapshot, Range<usize>, ExcerptId, Option<Anchor>)> + '_ {
|
||||
let start = range.start.to_offset(&self);
|
||||
let end = range.end.to_offset(&self);
|
||||
|
||||
let mut cursor = self.cursor::<usize>();
|
||||
cursor.seek(&start);
|
||||
|
||||
std::iter::from_fn(move || {
|
||||
let region = cursor.region()?;
|
||||
if region.range.start > end {
|
||||
return None;
|
||||
}
|
||||
let start_overshoot = start.saturating_sub(region.range.start);
|
||||
let end_overshoot = end.saturating_sub(region.range.start);
|
||||
let start = region
|
||||
.buffer_range
|
||||
.end
|
||||
.min(region.buffer_range.start + start_overshoot);
|
||||
let end = region
|
||||
.buffer_range
|
||||
.end
|
||||
.min(region.buffer_range.start + end_overshoot);
|
||||
|
||||
let region_excerpt_id = region.excerpt.id;
|
||||
let deleted_hunk_anchor = if region.is_main_buffer {
|
||||
None
|
||||
} else {
|
||||
Some(self.anchor_before(region.range.start))
|
||||
};
|
||||
let result = (
|
||||
region.buffer,
|
||||
start..end,
|
||||
region_excerpt_id,
|
||||
deleted_hunk_anchor,
|
||||
);
|
||||
cursor.next();
|
||||
Some(result)
|
||||
})
|
||||
}
|
||||
|
||||
/// Retrieves buffer metadata for the given range, and converts it into multi-buffer
|
||||
/// coordinates.
|
||||
///
|
||||
|
@ -4205,36 +4248,7 @@ impl MultiBufferSnapshot {
|
|||
where
|
||||
D: TextDimension + Ord + Sub<D, Output = D>,
|
||||
{
|
||||
let mut cursor = self.excerpts.cursor::<ExcerptSummary>(&());
|
||||
let locator = self.excerpt_locator_for_id(anchor.excerpt_id);
|
||||
|
||||
cursor.seek(locator, Bias::Left, &());
|
||||
if cursor.item().is_none() {
|
||||
cursor.next(&());
|
||||
}
|
||||
|
||||
let mut excerpt_position = D::from_text_summary(&cursor.start().text);
|
||||
if let Some(excerpt) = cursor.item() {
|
||||
if excerpt.id == anchor.excerpt_id {
|
||||
let excerpt_buffer_start =
|
||||
excerpt.range.context.start.summary::<D>(&excerpt.buffer);
|
||||
let excerpt_buffer_end = excerpt.range.context.end.summary::<D>(&excerpt.buffer);
|
||||
let buffer_position = cmp::min(
|
||||
excerpt_buffer_end,
|
||||
anchor.text_anchor.summary::<D>(&excerpt.buffer),
|
||||
);
|
||||
if buffer_position > excerpt_buffer_start {
|
||||
excerpt_position.add_assign(&(buffer_position - excerpt_buffer_start));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut diff_transforms_cursor = self
|
||||
.diff_transforms
|
||||
.cursor::<(ExcerptDimension<D>, OutputDimension<D>)>(&());
|
||||
diff_transforms_cursor.seek(&ExcerptDimension(excerpt_position), Bias::Left, &());
|
||||
|
||||
self.resolve_summary_for_anchor(anchor, excerpt_position, &mut diff_transforms_cursor)
|
||||
self.summaries_for_anchors([anchor])[0]
|
||||
}
|
||||
|
||||
fn resolve_summary_for_anchor<D>(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue