diff --git a/zed/src/editor/display_map.rs b/zed/src/editor/display_map.rs index a05115bafd..c3b45bee66 100644 --- a/zed/src/editor/display_map.rs +++ b/zed/src/editor/display_map.rs @@ -290,75 +290,10 @@ mod tests { language::{Language, LanguageConfig}, settings::Theme, test::*, - util::RandomCharIter, }; use buffer::History; use gpui::MutableAppContext; - use rand::prelude::*; - use std::{env, sync::Arc}; - - #[gpui::test] - async fn test_random(mut cx: gpui::TestAppContext) { - cx.foreground().set_block_on_ticks(usize::MAX..=usize::MAX); - let iterations = env::var("ITERATIONS") - .map(|i| i.parse().expect("invalid `ITERATIONS` variable")) - .unwrap_or(100); - let operations = env::var("OPERATIONS") - .map(|i| i.parse().expect("invalid `OPERATIONS` variable")) - .unwrap_or(10); - let seed_range = if let Ok(seed) = env::var("SEED") { - let seed = seed.parse().expect("invalid `SEED` variable"); - seed..seed + 1 - } else { - 0..iterations - }; - let font_cache = cx.font_cache(); - - for seed in seed_range { - dbg!(seed); - let mut rng = StdRng::seed_from_u64(seed); - let settings = Settings { - buffer_font_family: font_cache.load_family(&["Helvetica"]).unwrap(), - ui_font_family: font_cache.load_family(&["Helvetica"]).unwrap(), - buffer_font_size: 12.0, - ui_font_size: 12.0, - tab_size: rng.gen_range(1..=4), - theme: Arc::new(Theme::default()), - }; - - let buffer = cx.add_model(|cx| { - let len = rng.gen_range(0..10); - let text = RandomCharIter::new(&mut rng).take(len).collect::(); - log::info!("Initial buffer text: {:?}", text); - Buffer::new(0, text, cx) - }); - let wrap_width = Some(rng.gen_range(20.0..=100.0)); - let map = cx.add_model(|cx| DisplayMap::new(buffer.clone(), settings, wrap_width, cx)); - - for _op_ix in 0..operations { - buffer.update(&mut cx, |buffer, cx| buffer.randomly_mutate(&mut rng, cx)); - let snapshot = map.update(&mut cx, |map, cx| map.snapshot(cx)); - let expected_buffer_rows = (0..=snapshot.max_point().row()) - .map(|display_row| { - DisplayPoint::new(display_row, 0) - .to_buffer_point(&snapshot, Bias::Left) - .row - }) - .collect::>(); - for start_display_row in 0..expected_buffer_rows.len() { - assert_eq!( - snapshot - .buffer_rows(start_display_row as u32) - .map(|(row, _)| row) - .collect::>(), - &expected_buffer_rows[start_display_row..], - "invalid buffer_rows({}..)", - start_display_row - ); - } - } - } - } + use std::sync::Arc; #[gpui::test] async fn test_soft_wraps(mut cx: gpui::TestAppContext) { diff --git a/zed/src/editor/display_map/tab_map.rs b/zed/src/editor/display_map/tab_map.rs index fb11e08024..99257c847f 100644 --- a/zed/src/editor/display_map/tab_map.rs +++ b/zed/src/editor/display_map/tab_map.rs @@ -91,8 +91,8 @@ impl TabMap { #[derive(Clone)] pub struct Snapshot { - fold_snapshot: FoldSnapshot, - tab_size: usize, + pub fold_snapshot: FoldSnapshot, + pub tab_size: usize, } impl Snapshot { diff --git a/zed/src/editor/display_map/wrap_map.rs b/zed/src/editor/display_map/wrap_map.rs index d2f38971a8..94d45de2db 100644 --- a/zed/src/editor/display_map/wrap_map.rs +++ b/zed/src/editor/display_map/wrap_map.rs @@ -583,6 +583,31 @@ impl Snapshot { } } } + + let mut expected_buffer_rows = Vec::new(); + let mut buffer_row = 0; + let mut prev_tab_row = 0; + for display_row in 0..=self.max_point().row() { + let tab_point = self.to_tab_point(WrapPoint::new(display_row, 0)); + if tab_point.row() != prev_tab_row { + let fold_point = self.tab_snapshot.to_fold_point(tab_point, Bias::Left).0; + let buffer_point = fold_point.to_buffer_point(&self.tab_snapshot.fold_snapshot); + buffer_row = buffer_point.row; + prev_tab_row = tab_point.row(); + } + expected_buffer_rows.push(buffer_row); + } + + for start_display_row in 0..expected_buffer_rows.len() { + assert_eq!( + self.buffer_rows(start_display_row as u32) + .map(|(row, _)| row) + .collect::>(), + &expected_buffer_rows[start_display_row..], + "invalid buffer_rows({}..)", + start_display_row + ); + } } } }