git: Fix incorrect spacers for added or deleted files at the end of the multibuffer (#47525)

Cole Miller and Zed Zippy created

Release Notes:

- N/A

---------

Co-authored-by: Zed Zippy <234243425+zed-zippy[bot]@users.noreply.github.com>

Change summary

crates/editor/src/display_map/block_map.rs |  2 
crates/editor/src/split.rs                 | 76 ++++++++++++++++++++++++
2 files changed, 77 insertions(+), 1 deletion(-)

Detailed changes

crates/editor/src/display_map/block_map.rs 🔗

@@ -666,7 +666,7 @@ impl BlockMap {
 
                     let mut my_start = wrap_snapshot.make_wrap_point(my_start, Bias::Left);
                     let mut my_end = wrap_snapshot.make_wrap_point(my_end, Bias::Left);
-                    if my_end.column() > 0 {
+                    if my_end.column() > 0 || my_end == wrap_snapshot.max_point() {
                         *my_end.row_mut() += 1;
                         *my_end.column_mut() = 0;
                     }

crates/editor/src/split.rs 🔗

@@ -3356,6 +3356,82 @@ mod tests {
         );
     }
 
+    #[gpui::test]
+    async fn test_added_file_at_end(cx: &mut gpui::TestAppContext) {
+        use rope::Point;
+        use unindent::Unindent as _;
+
+        let (editor, mut cx) = init_test(cx).await;
+
+        let base_text = "";
+        let current_text = "
+            aaaa bbbb cccc dddd eeee ffff
+            bbb
+            ccc
+        "
+        .unindent();
+
+        let (buffer, diff) = buffer_with_diff(base_text, &current_text, &mut cx);
+
+        editor.update(cx, |editor, cx| {
+            let path = PathKey::for_buffer(&buffer, cx);
+            editor.set_excerpts_for_path(
+                path,
+                buffer.clone(),
+                vec![Point::new(0, 0)..buffer.read(cx).max_point()],
+                0,
+                diff.clone(),
+                cx,
+            );
+        });
+
+        cx.run_until_parked();
+
+        assert_split_content(
+            &editor,
+            "
+            § <no file>
+            § -----
+            aaaa bbbb cccc dddd eeee ffff
+            bbb
+            ccc"
+            .unindent(),
+            "
+            § <no file>
+            § -----
+            § spacer
+            § spacer
+            § spacer"
+                .unindent(),
+            &mut cx,
+        );
+
+        assert_split_content_with_widths(
+            &editor,
+            px(200.0),
+            px(200.0),
+            "
+            § <no file>
+            § -----
+            aaaa bbbb\x20
+            cccc dddd\x20
+            eeee ffff
+            bbb
+            ccc"
+            .unindent(),
+            "
+            § <no file>
+            § -----
+            § spacer
+            § spacer
+            § spacer
+            § spacer
+            § spacer"
+                .unindent(),
+            &mut cx,
+        );
+    }
+
     #[gpui::test]
     async fn test_adding_line_to_addition_hunk(cx: &mut gpui::TestAppContext) {
         use rope::Point;