Test longest row only when tabs are not present or the tab size is 1

Antonio Scandurra created

This is because the longest row calculation is best-effort at the moment,
since this information is not indexed in the `TabMap`.

Change summary

crates/editor/src/display_map/tab_map.rs  | 16 ++++----
crates/editor/src/display_map/wrap_map.rs | 44 ++++++++++++++----------
2 files changed, 34 insertions(+), 26 deletions(-)

Detailed changes

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

@@ -506,14 +506,14 @@ mod tests {
                     .map(|c| c.text)
                     .collect::<String>()
             );
-            assert_eq!(
-                TextSummary {
-                    longest_row: expected_summary.longest_row,
-                    longest_row_chars: expected_summary.longest_row_chars,
-                    ..tabs_snapshot.text_summary_for_range(start..end)
-                },
-                expected_summary,
-            );
+
+            let mut actual_summary = tabs_snapshot.text_summary_for_range(start..end);
+            if tab_size > 1 && folds_snapshot.text().contains('\t') {
+                actual_summary.longest_row = expected_summary.longest_row;
+                actual_summary.longest_row_chars = expected_summary.longest_row_chars;
+            }
+
+            assert_eq!(actual_summary, expected_summary,);
         }
     }
 }

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

@@ -1214,26 +1214,34 @@ mod tests {
                     log::info!("{} summary: {:?}", ix, item.summary.output,);
                 }
 
-                let mut expected_longest_rows = Vec::new();
-                let mut longest_line_len = -1;
-                for (row, line) in expected_text.split('\n').enumerate() {
-                    let line_char_count = line.chars().count() as isize;
-                    if line_char_count > longest_line_len {
-                        expected_longest_rows.clear();
-                        longest_line_len = line_char_count;
-                    }
-                    if line_char_count >= longest_line_len {
-                        expected_longest_rows.push(row as u32);
+                if tab_size == 1
+                    || !wrapped_snapshot
+                        .tab_snapshot
+                        .fold_snapshot
+                        .text()
+                        .contains('\t')
+                {
+                    let mut expected_longest_rows = Vec::new();
+                    let mut longest_line_len = -1;
+                    for (row, line) in expected_text.split('\n').enumerate() {
+                        let line_char_count = line.chars().count() as isize;
+                        if line_char_count > longest_line_len {
+                            expected_longest_rows.clear();
+                            longest_line_len = line_char_count;
+                        }
+                        if line_char_count >= longest_line_len {
+                            expected_longest_rows.push(row as u32);
+                        }
                     }
-                }
 
-                assert!(
-                    expected_longest_rows.contains(&actual_longest_row),
-                    "incorrect longest row {}. expected {:?} with length {}",
-                    actual_longest_row,
-                    expected_longest_rows,
-                    longest_line_len,
-                )
+                    assert!(
+                        expected_longest_rows.contains(&actual_longest_row),
+                        "incorrect longest row {}. expected {:?} with length {}",
+                        actual_longest_row,
+                        expected_longest_rows,
+                        longest_line_len,
+                    )
+                }
             }
         }