@@ -5567,13 +5567,6 @@ impl EditorElement {
if row_infos[row_ix].diff_status.is_none() {
continue;
}
- if row_infos[row_ix]
- .diff_status
- .is_some_and(|status| status.is_added())
- && !status.is_added()
- {
- continue;
- }
if active_positions
.iter()
@@ -4141,6 +4141,14 @@ impl MultiBufferSnapshot {
&& region.range.start > MBD::default()
{
cursor.prev()
+ } else if let Some(region) = cursor.region()
+ && region.is_main_buffer
+ && region.diff_hunk_status.is_some()
+ {
+ cursor.prev();
+ if cursor.region().is_none_or(|region| region.is_main_buffer) {
+ cursor.next();
+ }
}
iter::from_fn(move || {
@@ -4193,9 +4201,11 @@ impl MultiBufferSnapshot {
// the metadata item's range.
if metadata_buffer_range.start > <MBD::TextDimension>::default() {
while let Some(region) = cursor.region() {
- if region.is_main_buffer
+ if (region.is_main_buffer
&& (region.buffer_range.end >= metadata_buffer_range.start
- || cursor.is_at_end_of_excerpt())
+ || cursor.is_at_end_of_excerpt()))
+ || (!region.is_main_buffer
+ && region.buffer_range.start == metadata_buffer_range.start)
{
break;
}
@@ -473,6 +473,47 @@ async fn test_diff_hunks_in_range(cx: &mut TestAppContext) {
);
}
+#[gpui::test]
+async fn test_diff_hunks_in_range_query_starting_at_added_row(cx: &mut TestAppContext) {
+ let base_text = "one\ntwo\nthree\n";
+ let text = "one\nTWO\nthree\n";
+ let buffer = cx.new(|cx| Buffer::local(text, cx));
+ let diff = cx
+ .new(|cx| BufferDiff::new_with_base_text(base_text, &buffer.read(cx).text_snapshot(), cx));
+ let multibuffer = cx.new(|cx| MultiBuffer::singleton(buffer, cx));
+ let (mut snapshot, mut subscription) = multibuffer.update(cx, |multibuffer, cx| {
+ (multibuffer.snapshot(cx), multibuffer.subscribe())
+ });
+
+ multibuffer.update(cx, |multibuffer, cx| {
+ multibuffer.add_diff(diff, cx);
+ multibuffer.expand_diff_hunks(vec![Anchor::min()..Anchor::max()], cx);
+ });
+
+ assert_new_snapshot(
+ &multibuffer,
+ &mut snapshot,
+ &mut subscription,
+ cx,
+ indoc! {
+ " one
+ - two
+ + TWO
+ three
+ "
+ },
+ );
+
+ assert_eq!(
+ snapshot
+ .diff_hunks_in_range(Point::new(2, 0)..Point::MAX)
+ .map(|hunk| hunk.row_range.start.0..hunk.row_range.end.0)
+ .collect::<Vec<_>>(),
+ vec![1..3],
+ "querying starting at the added row should still return the full hunk including deleted lines"
+ );
+}
+
#[gpui::test]
async fn test_inverted_diff_hunks_in_range(cx: &mut TestAppContext) {
let base_text = "one\ntwo\nthree\nfour\nfive\nsix\nseven\neight\n";