Return back the logic for indent guides check (#22095)

Kirill Bulatov and Bennet created

Follow-up of https://github.com/zed-industries/zed/pull/22046

Release Notes:

- N/A

Co-authored-by: Bennet <bennet@zed.dev>

Change summary

crates/editor/src/editor_tests.rs  |  1 +
crates/editor/src/indent_guides.rs | 14 +++++++++++++-
2 files changed, 14 insertions(+), 1 deletion(-)

Detailed changes

crates/editor/src/editor_tests.rs 🔗

@@ -13078,6 +13078,7 @@ fn assert_indent_guides(
     let indent_guides = cx.update_editor(|editor, cx| {
         let snapshot = editor.snapshot(cx).display_snapshot;
         let mut indent_guides: Vec<_> = crate::indent_guides::indent_guides_in_range(
+            editor,
             MultiBufferRow(range.start)..MultiBufferRow(range.end),
             true,
             &snapshot,

crates/editor/src/indent_guides.rs 🔗

@@ -56,6 +56,7 @@ impl Editor {
         }
 
         Some(indent_guides_in_range(
+            self,
             visible_buffer_range,
             self.should_show_indent_guides() == Some(true),
             snapshot,
@@ -152,6 +153,7 @@ impl Editor {
 }
 
 pub fn indent_guides_in_range(
+    editor: &Editor,
     visible_buffer_range: Range<MultiBufferRow>,
     ignore_disabled_for_language: bool,
     snapshot: &DisplaySnapshot,
@@ -169,10 +171,20 @@ pub fn indent_guides_in_range(
         .indent_guides_in_range(start_anchor..end_anchor, ignore_disabled_for_language, cx)
         .into_iter()
         .filter(|indent_guide| {
+            if editor.buffer_folded(indent_guide.buffer_id, cx) {
+                return false;
+            }
+
             let start =
                 MultiBufferRow(indent_guide.multibuffer_row_range.start.0.saturating_sub(1));
             // Filter out indent guides that are inside a fold
-            !snapshot.is_line_folded(start)
+            // All indent guides that are starting "offscreen" have a start value of the first visible row minus one
+            // Therefore checking if a line is folded at first visible row minus one causes the other indent guides that are not related to the fold to disappear as well
+            let is_folded = snapshot.is_line_folded(start);
+            let line_indent = snapshot.line_indent_for_buffer_row(start);
+            let contained_in_fold =
+                line_indent.len(indent_guide.tab_size) <= indent_guide.indent_level();
+            !(is_folded && contained_in_fold)
         })
         .collect()
 }