From 5c1f82ae3da9c15de1f74023bbae30a0c2115d33 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 28 Mar 2023 17:37:57 -0700 Subject: [PATCH] Don't use TabMap::expand_tabs in line_indent_for_buffer_row --- crates/editor/src/display_map.rs | 25 +++++++++++------------- crates/editor/src/display_map/tab_map.rs | 2 +- crates/editor/src/editor_tests.rs | 2 +- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/crates/editor/src/display_map.rs b/crates/editor/src/display_map.rs index cdad986b49..4d83135205 100644 --- a/crates/editor/src/display_map.rs +++ b/crates/editor/src/display_map.rs @@ -634,24 +634,21 @@ impl DisplaySnapshot { .buffer_snapshot .buffer_line_for_row(buffer_row) .unwrap(); - let chars = buffer.chars_at(Point::new(range.start.row, 0)); + let mut indent_size = 0; let mut is_blank = false; - let indent_size = self.tab_snapshot.expand_tabs( - chars.take_while(|c| { - if *c == ' ' || *c == '\t' { - true - } else { - if *c == '\n' { - is_blank = true; - } - false + for c in buffer.chars_at(Point::new(range.start.row, 0)) { + if c == ' ' || c == '\t' { + indent_size += 1; + } else { + if c == '\n' { + is_blank = true; } - }), - buffer.line_len(buffer_row), // Never collapse - ); + break; + } + } - (indent_size as u32, is_blank) + (indent_size, is_blank) } pub fn line_len(&self, row: u32) -> u32 { diff --git a/crates/editor/src/display_map/tab_map.rs b/crates/editor/src/display_map/tab_map.rs index 55b3425b24..50dc691a60 100644 --- a/crates/editor/src/display_map/tab_map.rs +++ b/crates/editor/src/display_map/tab_map.rs @@ -290,7 +290,7 @@ impl TabSnapshot { fold_point.to_buffer_point(&self.suggestion_snapshot.fold_snapshot) } - pub fn expand_tabs(&self, chars: impl Iterator, column: u32) -> u32 { + fn expand_tabs(&self, chars: impl Iterator, column: u32) -> u32 { let tab_size = self.tab_size.get(); let mut expanded_chars = 0; diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rs index 4f61bde398..292c24f79a 100644 --- a/crates/editor/src/editor_tests.rs +++ b/crates/editor/src/editor_tests.rs @@ -630,7 +630,7 @@ fn test_cancel(cx: &mut gpui::MutableAppContext) { } #[gpui::test] -fn test_fold(cx: &mut gpui::MutableAppContext) { +fn test_fold_action(cx: &mut gpui::MutableAppContext) { cx.set_global(Settings::test(cx)); let buffer = MultiBuffer::build_simple( &"