From 1c4c568068b067f08b03e6cdf53e80d86fa35966 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Fri, 28 Feb 2025 16:02:35 -0800 Subject: [PATCH] Allow unfolding deleted buffers in project diff w/ keyboard (#25835) Release Notes: - N/A --- crates/editor/src/editor.rs | 19 ++++++++++--------- crates/multi_buffer/src/multi_buffer.rs | 4 +++- crates/multi_buffer/src/multi_buffer_tests.rs | 19 +++++++++++++++++++ 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 47eb8495e9b157bf5f54a1c9c323de2a6045560f..dc0f5fc88b549e74dea7b6aa7fb30cfdaf0b3591 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -13018,11 +13018,11 @@ impl Editor { self.fold_creases(to_fold, true, window, cx); } else { let multi_buffer_snapshot = self.buffer.read(cx).snapshot(cx); - - let buffer_ids: HashSet<_> = multi_buffer_snapshot - .ranges_to_buffer_ranges(self.selections.disjoint_anchor_ranges()) - .map(|(snapshot, _, _)| snapshot.remote_id()) - .collect(); + let buffer_ids = self + .selections + .disjoint_anchor_ranges() + .flat_map(|range| multi_buffer_snapshot.buffer_ids_for_range(range)) + .collect::>(); for buffer_id in buffer_ids { self.fold_buffer(buffer_id, cx); } @@ -13195,10 +13195,11 @@ impl Editor { self.unfold_ranges(&ranges, true, true, cx); } else { let multi_buffer_snapshot = self.buffer.read(cx).snapshot(cx); - let buffer_ids: HashSet<_> = multi_buffer_snapshot - .ranges_to_buffer_ranges(self.selections.disjoint_anchor_ranges()) - .map(|(snapshot, _, _)| snapshot.remote_id()) - .collect(); + let buffer_ids = self + .selections + .disjoint_anchor_ranges() + .flat_map(|range| multi_buffer_snapshot.buffer_ids_for_range(range)) + .collect::>(); for buffer_id in buffer_ids { self.unfold_buffer(buffer_id, cx); } diff --git a/crates/multi_buffer/src/multi_buffer.rs b/crates/multi_buffer/src/multi_buffer.rs index 21d657775f8fe8a72b33e7a06ada672ba2d7566a..e943e797ab2e4c3b2db2e6e2e7d99d8e3c644570 100644 --- a/crates/multi_buffer/src/multi_buffer.rs +++ b/crates/multi_buffer/src/multi_buffer.rs @@ -3541,7 +3541,9 @@ impl MultiBufferSnapshot { cursor.seek(&range.start); std::iter::from_fn(move || { let region = cursor.region()?; - if region.range.start >= range.end { + if region.range.start > range.end + || region.range.start == range.end && region.range.start > range.start + { return None; } cursor.next_excerpt(); diff --git a/crates/multi_buffer/src/multi_buffer_tests.rs b/crates/multi_buffer/src/multi_buffer_tests.rs index e878e50dd22478d0cb1507024508af5ea7baf863..bac946ba84b57bcf0afeb113c6879ebf5253c044 100644 --- a/crates/multi_buffer/src/multi_buffer_tests.rs +++ b/crates/multi_buffer/src/multi_buffer_tests.rs @@ -2035,6 +2035,25 @@ fn test_diff_hunks_with_multiple_excerpts(cx: &mut TestAppContext) { ] ); + let buffer_ids_by_range = [ + (Point::new(0, 0)..Point::new(0, 0), &[id_1] as &[_]), + (Point::new(0, 0)..Point::new(2, 0), &[id_1]), + (Point::new(2, 0)..Point::new(2, 0), &[id_1]), + (Point::new(3, 0)..Point::new(3, 0), &[id_1]), + (Point::new(8, 0)..Point::new(9, 0), &[id_1]), + (Point::new(8, 0)..Point::new(10, 0), &[id_1, id_2]), + (Point::new(9, 0)..Point::new(9, 0), &[id_2]), + ]; + for (range, buffer_ids) in buffer_ids_by_range { + assert_eq!( + snapshot + .buffer_ids_for_range(range.clone()) + .collect::>(), + buffer_ids, + "buffer_ids_for_range({range:?}" + ); + } + assert_position_translation(&snapshot); assert_line_indents(&snapshot);