diff --git a/zed/src/editor/buffer/mod.rs b/zed/src/editor/buffer/mod.rs index 89229dc5f7..6ac8b2c2c0 100644 --- a/zed/src/editor/buffer/mod.rs +++ b/zed/src/editor/buffer/mod.rs @@ -692,7 +692,6 @@ impl Buffer { fn autoindent_for_rows(&self, rows: Range) -> Vec { let mut indents = Vec::new(); - let mut indent = 2; if let Some((language, syntax_tree)) = self.language.as_ref().zip(self.syntax_tree()) { let mut stack = Vec::new(); let mut cursor = syntax_tree.walk(); @@ -855,6 +854,10 @@ impl Buffer { self.visible_text.max_point() } + pub fn row_count(&self) -> u32 { + self.max_point().row + 1 + } + pub fn text(&self) -> String { self.text_for_range(0..self.len()).collect() } @@ -3757,7 +3760,7 @@ mod tests { buffer.condition(&ctx, |buf, _| !buf.is_parsing()).await; buffer.read_with(&ctx, |buf, _| { assert_eq!( - buf.autoindent_for_rows(0..buf.max_point().row + 1), + buf.autoindent_for_rows(0..buf.row_count()), vec![0, 0, 0, 0, 0, 0, 3, 3, 0, 0, 0, 0, 0, 0, 0] ); todo!("write assertions to test how indents work with different subset of rows"); diff --git a/zed/src/editor/buffer_view.rs b/zed/src/editor/buffer_view.rs index 15bc94feec..e2516d2113 100644 --- a/zed/src/editor/buffer_view.rs +++ b/zed/src/editor/buffer_view.rs @@ -2074,10 +2074,7 @@ impl BufferView { let font_size = settings.buffer_font_size; let font_id = font_cache.select_font(settings.buffer_font_family, &FontProperties::new())?; - let digit_count = ((self.buffer.read(app).max_point().row + 1) as f32) - .log10() - .floor() as usize - + 1; + let digit_count = (self.buffer.read(app).row_count() as f32).log10().floor() as usize + 1; Ok(layout_cache .layout_str(