From 835af3583982666f49b9248177507128aaa5a393 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Fri, 24 Dec 2021 20:50:26 -0700 Subject: [PATCH] Simplify prev/next_row_boundary methods We added clipping of points against the buffer when excerpt headers were in the buffer, but now that they're just blocks, I think we can avoid the potential to panic in these methods by going back to not clipping. --- crates/editor/src/display_map.rs | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/crates/editor/src/display_map.rs b/crates/editor/src/display_map.rs index bcf7d14906..cb6b020aff 100644 --- a/crates/editor/src/display_map.rs +++ b/crates/editor/src/display_map.rs @@ -200,38 +200,28 @@ impl DisplaySnapshot { self.buffer_snapshot.max_buffer_row() } - pub fn prev_row_boundary(&self, input_display_point: DisplayPoint) -> (DisplayPoint, Point) { - let mut display_point = input_display_point; + pub fn prev_row_boundary(&self, mut display_point: DisplayPoint) -> (DisplayPoint, Point) { loop { *display_point.column_mut() = 0; 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_with_clipping(point, Bias::Left); + let next_display_point = self.point_to_display_point(point, Bias::Left); if next_display_point == display_point { return (display_point, point); } - if next_display_point > display_point { - panic!("invalid display point {:?}", input_display_point); - } display_point = next_display_point; } } - pub fn next_row_boundary(&self, input_display_point: DisplayPoint) -> (DisplayPoint, Point) { - let mut display_point = input_display_point; + pub fn next_row_boundary(&self, mut display_point: DisplayPoint) -> (DisplayPoint, Point) { loop { *display_point.column_mut() = self.line_len(display_point.row()); - let mut point = self.display_point_to_point(display_point, Bias::Right); - point = self.buffer_snapshot.clip_point(point, Bias::Right); + let mut point = display_point.to_point(self); point.column = self.buffer_snapshot.line_len(point.row); let next_display_point = self.point_to_display_point(point, Bias::Right); if next_display_point == display_point { return (display_point, point); } - if next_display_point < display_point { - panic!("invalid display point {:?}", input_display_point); - } display_point = next_display_point; } }