Fix stale hunks after commit (#24663)

Fixes a regression introduced in #24475.

Release Notes:

- N/A
This commit is contained in:
Cole Miller 2025-02-11 11:39:57 -05:00 committed by GitHub
parent bbea3a2184
commit 6e7416eb00
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 14 deletions

View file

@ -587,18 +587,16 @@ impl BufferDiff {
range: Range<Anchor>,
buffer: &text::BufferSnapshot,
cx: &App,
) -> Option<Range<Anchor>> {
) -> Range<Anchor> {
let start = self
.hunks_intersecting_range(range.clone(), &buffer, cx)
.next()?
.buffer_range
.start;
.next()
.map_or(Anchor::MIN, |hunk| hunk.buffer_range.start);
let end = self
.hunks_intersecting_range_rev(range.clone(), &buffer)
.next()?
.buffer_range
.end;
Some(start..end)
.next()
.map_or(Anchor::MAX, |hunk| hunk.buffer_range.end);
start..end
}
#[allow(clippy::too_many_arguments)]

View file

@ -260,15 +260,12 @@ impl BufferDiffState {
let changed_range = match (unstaged_changed_range, uncommitted_changed_range) {
(None, None) => None,
(Some(unstaged_range), None) => {
uncommitted_diff.range_to_hunk_range(unstaged_range, &buffer, cx)
Some(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 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(start..end)