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

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

Release Notes:

- N/A

Co-authored-by: Bennet <bennet@zed.dev>
This commit is contained in:
Kirill Bulatov 2024-12-16 22:53:14 +02:00 committed by GitHub
parent 8127decd2d
commit 91fdb5d2a9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View file

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

View file

@ -56,6 +56,7 @@ impl Editor {
} }
Some(indent_guides_in_range( Some(indent_guides_in_range(
self,
visible_buffer_range, visible_buffer_range,
self.should_show_indent_guides() == Some(true), self.should_show_indent_guides() == Some(true),
snapshot, snapshot,
@ -152,6 +153,7 @@ impl Editor {
} }
pub fn indent_guides_in_range( pub fn indent_guides_in_range(
editor: &Editor,
visible_buffer_range: Range<MultiBufferRow>, visible_buffer_range: Range<MultiBufferRow>,
ignore_disabled_for_language: bool, ignore_disabled_for_language: bool,
snapshot: &DisplaySnapshot, 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) .indent_guides_in_range(start_anchor..end_anchor, ignore_disabled_for_language, cx)
.into_iter() .into_iter()
.filter(|indent_guide| { .filter(|indent_guide| {
if editor.buffer_folded(indent_guide.buffer_id, cx) {
return false;
}
let start = let start =
MultiBufferRow(indent_guide.multibuffer_row_range.start.0.saturating_sub(1)); MultiBufferRow(indent_guide.multibuffer_row_range.start.0.saturating_sub(1));
// Filter out indent guides that are inside a fold // 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() .collect()
} }