Use correct range to get diff hunks in the presence of wrapped lines

Julia created

Change summary

crates/editor/src/display_map/block_map.rs |  1 +
crates/editor/src/display_map/fold_map.rs  |  1 +
crates/editor/src/display_map/wrap_map.rs  |  1 +
crates/editor/src/element.rs               | 18 +++++++++++++++---
crates/editor/src/multi_buffer.rs          |  1 +
5 files changed, 19 insertions(+), 3 deletions(-)

Detailed changes

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

@@ -157,6 +157,7 @@ pub struct BlockChunks<'a> {
     max_output_row: u32,
 }
 
+#[derive(Clone)]
 pub struct BlockBufferRows<'a> {
     transforms: sum_tree::Cursor<'a, Transform, (BlockRow, WrapRow)>,
     input_buffer_rows: wrap_map::WrapBufferRows<'a>,

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

@@ -987,6 +987,7 @@ impl<'a> sum_tree::Dimension<'a, FoldSummary> for usize {
     }
 }
 
+#[derive(Clone)]
 pub struct FoldBufferRows<'a> {
     cursor: Cursor<'a, Transform, (FoldPoint, Point)>,
     input_buffer_rows: MultiBufferRows<'a>,

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

@@ -62,6 +62,7 @@ pub struct WrapChunks<'a> {
     transforms: Cursor<'a, Transform, (WrapPoint, TabPoint)>,
 }
 
+#[derive(Clone)]
 pub struct WrapBufferRows<'a> {
     input_buffer_rows: fold_map::FoldBufferRows<'a>,
     input_buffer_row: Option<u32>,

crates/editor/src/element.rs 🔗

@@ -1042,15 +1042,27 @@ impl EditorElement {
         rows: Range<u32>,
         snapshot: &EditorSnapshot,
     ) -> Vec<DiffHunkLayout> {
+        let buffer_rows = snapshot.buffer_rows(rows.start);
+        let start_actual_row = match buffer_rows
+            .clone()
+            .take((rows.end - rows.start) as usize)
+            .find_map(|b| b)
+        {
+            Some(start_actual_row) => start_actual_row,
+            None => return Vec::new(),
+        };
+
+        //Get all hunks after our starting actual buffer row
+        //The loop is in terms of visual buffer rows so we simply
+        //return before touching any hunks past the end of the view
         let mut diff_hunks = snapshot
             .buffer_snapshot
-            .git_diff_hunks_in_range(rows.clone())
+            .git_diff_hunks_in_range(start_actual_row..u32::MAX)
             .peekable();
 
         //Some number followed by Nones for wrapped lines
         //Jump in number for folded lines
-        let mut buffer_rows = snapshot
-            .buffer_rows(rows.start)
+        let mut buffer_rows = buffer_rows
             .take((rows.end - rows.start) as usize)
             .enumerate()
             .peekable();

crates/editor/src/multi_buffer.rs 🔗

@@ -143,6 +143,7 @@ struct ExcerptSummary {
     text: TextSummary,
 }
 
+#[derive(Clone)]
 pub struct MultiBufferRows<'a> {
     buffer_row_range: Range<u32>,
     excerpts: Cursor<'a, Excerpt, Point>,