Fix issues with adjacent diff hunks (#25367)

Closes #ISSUE

Release Notes:

- Fixed being unable to toggle diff hunks with the mouse in some cases
This commit is contained in:
Cole Miller 2025-02-21 19:07:04 -05:00 committed by GitHub
parent 4118f42d61
commit ef53f7af22
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 193 additions and 39 deletions

View file

@ -2388,6 +2388,23 @@ impl MultiBuffer {
.is_some()
}
pub fn single_hunk_is_expanded(&self, range: Range<Anchor>, cx: &App) -> bool {
let snapshot = self.read(cx);
let mut cursor = snapshot.diff_transforms.cursor::<usize>(&());
let offset_range = range.to_offset(&snapshot);
cursor.seek(&offset_range.start, Bias::Right, &());
while let Some(item) = cursor.item() {
if *cursor.start() >= offset_range.end && *cursor.start() > offset_range.start {
break;
}
if item.hunk_info().is_some() {
return true;
}
cursor.next(&());
}
false
}
pub fn has_expanded_diff_hunks_in_ranges(&self, ranges: &[Range<Anchor>], cx: &App) -> bool {
let snapshot = self.read(cx);
let mut cursor = snapshot.diff_transforms.cursor::<usize>(&());
@ -2411,9 +2428,9 @@ impl MultiBuffer {
false
}
fn expand_or_collapse_diff_hunks_internal(
pub fn expand_or_collapse_diff_hunks_inner(
&mut self,
ranges: impl Iterator<Item = (Range<Point>, ExcerptId)>,
ranges: impl IntoIterator<Item = (Range<Point>, ExcerptId)>,
expand: bool,
cx: &mut Context<Self>,
) {
@ -2459,22 +2476,6 @@ impl MultiBuffer {
});
}
pub fn expand_or_collapse_diff_hunks_narrow(
&mut self,
ranges: Vec<Range<Anchor>>,
expand: bool,
cx: &mut Context<Self>,
) {
let snapshot = self.snapshot.borrow().clone();
self.expand_or_collapse_diff_hunks_internal(
ranges
.iter()
.map(move |range| (range.to_point(&snapshot), range.end.excerpt_id)),
expand,
cx,
);
}
pub fn expand_or_collapse_diff_hunks(
&mut self,
ranges: Vec<Range<Anchor>>,
@ -2482,19 +2483,16 @@ impl MultiBuffer {
cx: &mut Context<Self>,
) {
let snapshot = self.snapshot.borrow().clone();
self.expand_or_collapse_diff_hunks_internal(
ranges.iter().map(move |range| {
let end_excerpt_id = range.end.excerpt_id;
let range = range.to_point(&snapshot);
let mut peek_end = range.end;
if range.end.row < snapshot.max_row().0 {
peek_end = Point::new(range.end.row + 1, 0);
};
(range.start..peek_end, end_excerpt_id)
}),
expand,
cx,
);
let ranges = ranges.iter().map(move |range| {
let end_excerpt_id = range.end.excerpt_id;
let range = range.to_point(&snapshot);
let mut peek_end = range.end;
if range.end.row < snapshot.max_row().0 {
peek_end = Point::new(range.end.row + 1, 0);
};
(range.start..peek_end, end_excerpt_id)
});
self.expand_or_collapse_diff_hunks_inner(ranges, expand, cx);
}
pub fn resize_excerpt(