Touch up stale hunks fix (#24669)
Release Notes: - N/A Co-authored-by: Max <max@zed.dev>
This commit is contained in:
parent
7c00eec08b
commit
759ea0ec48
2 changed files with 19 additions and 13 deletions
|
@ -587,16 +587,18 @@ impl BufferDiff {
|
|||
range: Range<Anchor>,
|
||||
buffer: &text::BufferSnapshot,
|
||||
cx: &App,
|
||||
) -> Range<Anchor> {
|
||||
) -> Option<Range<Anchor>> {
|
||||
let start = self
|
||||
.hunks_intersecting_range(range.clone(), &buffer, cx)
|
||||
.next()
|
||||
.map_or(Anchor::MIN, |hunk| hunk.buffer_range.start);
|
||||
.next()?
|
||||
.buffer_range
|
||||
.start;
|
||||
let end = self
|
||||
.hunks_intersecting_range_rev(range.clone(), &buffer)
|
||||
.next()
|
||||
.map_or(Anchor::MAX, |hunk| hunk.buffer_range.end);
|
||||
start..end
|
||||
.next()?
|
||||
.buffer_range
|
||||
.end;
|
||||
Some(start..end)
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
|
|
|
@ -260,16 +260,20 @@ impl BufferDiffState {
|
|||
let changed_range = match (unstaged_changed_range, uncommitted_changed_range) {
|
||||
(None, None) => None,
|
||||
(Some(unstaged_range), None) => {
|
||||
Some(uncommitted_diff.range_to_hunk_range(unstaged_range, &buffer, cx))
|
||||
uncommitted_diff.range_to_hunk_range(unstaged_range, &buffer, cx)
|
||||
}
|
||||
(None, Some(uncommitted_range)) => Some(uncommitted_range),
|
||||
(Some(unstaged_range), Some(uncommitted_range)) => maybe!({
|
||||
let expanded_range =
|
||||
uncommitted_diff.range_to_hunk_range(unstaged_range, &buffer, cx);
|
||||
let start = expanded_range.start.min(&uncommitted_range.start, &buffer);
|
||||
let end = expanded_range.end.max(&uncommitted_range.end, &buffer);
|
||||
(Some(unstaged_range), Some(uncommitted_range)) => {
|
||||
let mut start = uncommitted_range.start;
|
||||
let mut end = uncommitted_range.end;
|
||||
if let Some(unstaged_range) =
|
||||
uncommitted_diff.range_to_hunk_range(unstaged_range, &buffer, cx)
|
||||
{
|
||||
start = unstaged_range.start.min(&uncommitted_range.start, &buffer);
|
||||
end = unstaged_range.end.max(&uncommitted_range.end, &buffer);
|
||||
}
|
||||
Some(start..end)
|
||||
}),
|
||||
}
|
||||
};
|
||||
cx.emit(BufferDiffEvent::DiffChanged { changed_range });
|
||||
})?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue