From 3e2f68454556e5246b99b7645dca11501689093b Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 15 Dec 2021 18:30:09 -0800 Subject: [PATCH] Fix prev_row_boundary when a wrap follows a fold Co-Authored-By: Nathan Sobo --- crates/editor/src/display_map.rs | 14 ++++++++++++-- crates/editor/src/display_map/wrap_map.rs | 9 +++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/crates/editor/src/display_map.rs b/crates/editor/src/display_map.rs index 2bea6536a2..220614ffd6 100644 --- a/crates/editor/src/display_map.rs +++ b/crates/editor/src/display_map.rs @@ -210,7 +210,7 @@ impl DisplaySnapshot { let mut point = display_point.to_point(self); point = self.buffer_snapshot.clip_point(point, Bias::Left); point.column = 0; - let next_display_point = self.point_to_display_point(point, Bias::Left); + let next_display_point = self.point_to_display_point_with_clipping(point, Bias::Left); if next_display_point == display_point { return (display_point, point); } @@ -252,6 +252,16 @@ impl DisplaySnapshot { DisplayPoint(block_point) } + fn point_to_display_point_with_clipping(&self, point: Point, bias: Bias) -> DisplayPoint { + let fold_point = point.to_fold_point(&self.folds_snapshot, bias); + let tab_point = self.tabs_snapshot.to_tab_point(fold_point); + let wrap_point = self + .wraps_snapshot + .from_tab_point_with_clipping(tab_point, bias); + let block_point = self.blocks_snapshot.to_block_point(wrap_point); + DisplayPoint(block_point) + } + fn display_point_to_point(&self, point: DisplayPoint, bias: Bias) -> Point { let block_point = point.0; let wrap_point = self.blocks_snapshot.to_wrap_point(block_point); @@ -492,7 +502,7 @@ mod tests { use Bias::*; #[gpui::test(iterations = 100)] - async fn test_random(mut cx: gpui::TestAppContext, mut rng: StdRng) { + async fn test_random_display_map(mut cx: gpui::TestAppContext, mut rng: StdRng) { cx.foreground().set_block_on_ticks(0..=50); cx.foreground().forbid_parking(); let operations = env::var("OPERATIONS") diff --git a/crates/editor/src/display_map/wrap_map.rs b/crates/editor/src/display_map/wrap_map.rs index b674b467c9..0dd91b7404 100644 --- a/crates/editor/src/display_map/wrap_map.rs +++ b/crates/editor/src/display_map/wrap_map.rs @@ -672,6 +672,15 @@ impl WrapSnapshot { WrapPoint(cursor.start().1 .0 + (point.0 - cursor.start().0 .0)) } + pub fn from_tab_point_with_clipping(&self, point: TabPoint, bias: Bias) -> WrapPoint { + let mut cursor = self.transforms.cursor::<(TabPoint, WrapPoint)>(); + cursor.seek(&point, bias, &()); + self.clip_point( + WrapPoint(cursor.start().1 .0 + (point.0 - cursor.start().0 .0)), + bias, + ) + } + pub fn clip_point(&self, mut point: WrapPoint, bias: Bias) -> WrapPoint { if bias == Bias::Left { let mut cursor = self.transforms.cursor::();