Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Make folds tab aware
Mikayla Maki5a3d5dff42bf
diff --git a/crates/editor/src/display_map.rs b/crates/editor/src/display_map.rsindex 8abc706dd7b..fe960b42d32 100644--- a/crates/editor/src/display_map.rs+++ b/crates/editor/src/display_map.rs@@ -24,6 +24,8 @@ pub use block_map::{BlockDisposition, BlockId, BlockProperties, BlockStyle, RenderBlock, TransformBlock,};+use self::tab_map::TabSnapshot;+#[derive(Copy, Clone, Debug, PartialEq, Eq)]pub enum FoldStatus {Folded,@@ -249,7 +251,7 @@ pub struct DisplaySnapshot {folds_snapshot: fold_map::FoldSnapshot,tabs_snapshot: tab_map::TabSnapshot,wraps_snapshot: wrap_map::WrapSnapshot,- pub blocks_snapshot: block_map::BlockSnapshot,+ blocks_snapshot: block_map::BlockSnapshot,text_highlights: TextHighlights,clip_at_line_ends: bool,}@@ -599,17 +601,22 @@ impl DisplaySnapshot {let chars = buffer.chars_at(Point::new(range.start.row, 0));let mut is_blank = false;- let mut indent_size = 0;- for c in chars {- // TODO: Handle tab expansion here- if c == ' ' {- indent_size += 1;- } else {- is_blank = c == '\n';- break;- }- }- (indent_size, is_blank)+ let indent_size = TabSnapshot::expand_tabs(+ chars.take_while(|c| {+ if *c == ' ' || *c == '\t' {+ true+ } else {+ if *c == '\n' {+ is_blank = true;+ }+ false+ }+ }),+ buffer.line_len(buffer_row) as usize, // Never collapse+ self.tabs_snapshot.tab_size,+ );++ (indent_size as u32, is_blank)}pub fn line_len(&self, row: u32) -> u32 {diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rsindex 92ec518c88f..4f61bde3987 100644--- a/crates/editor/src/editor_tests.rs+++ b/crates/editor/src/editor_tests.rs@@ -679,7 +679,7 @@ fn test_fold(cx: &mut gpui::MutableAppContext) {".unindent(),);- dbg!("SECOND FOLD");+view.fold(&Fold, cx);assert_eq!(view.display_text(cx),