From 3dd5b3f426aeb8c297bb839980476b0c972bb3a1 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Thu, 2 Mar 2023 19:42:59 -0800 Subject: [PATCH] Attempted to initialize code-fold indicators, does not work --- crates/editor/src/display_map.rs | 1 - crates/editor/src/editor.rs | 52 +++++++++++++++++++++++--------- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/crates/editor/src/display_map.rs b/crates/editor/src/display_map.rs index 229ecc34fe..38d5242321 100644 --- a/crates/editor/src/display_map.rs +++ b/crates/editor/src/display_map.rs @@ -643,7 +643,6 @@ impl DisplaySnapshot { break; } } - let end = end.unwrap_or(max_point); Some(start..end) } else { diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index cb9bf4da6c..643dd5b951 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -1196,6 +1196,19 @@ impl Editor { if mode == EditorMode::Full { let should_auto_hide_scrollbars = cx.platform().should_auto_hide_scrollbars(); cx.set_global(ScrollbarAutoHide(should_auto_hide_scrollbars)); + + // TODO: this does not work at all + let display_snapshot = this.snapshot(cx).display_snapshot; + let editor_snapshot = this.snapshot(cx); + if buffer.read(cx).is_singleton() { + this.insert_fold_styles( + display_snapshot + .folds_in_range(Anchor::min()..Anchor::max()) + .cloned(), + &editor_snapshot, + cx, + ) + } } this.report_event("open editor", cx); @@ -5865,26 +5878,35 @@ impl Editor { let snapshot = self.snapshot(cx); let anchor_ranges = offset_to_anchors(ranges, &snapshot); - self.change_click_ranges::(cx, |click_ranges| { - for range in anchor_ranges { - if let Err(idx) = click_ranges.binary_search_by(|click_range| { - click_range.cmp(&range, &snapshot.buffer_snapshot) - }) { - click_ranges.insert(idx, range) - } - } - }); - let click_ranges = self.clone_click_ranges::(); - self.highlight_background::( - click_ranges, - |theme| theme.editor.document_highlight_write_background, - cx, - ); + self.insert_fold_styles(anchor_ranges, &snapshot, cx); cx.notify(); } } + fn insert_fold_styles( + &mut self, + anchor_ranges: impl Iterator>, + snapshot: &EditorSnapshot, + cx: &mut ViewContext, + ) { + self.change_click_ranges::(cx, |click_ranges| { + for range in anchor_ranges { + if let Err(idx) = click_ranges.binary_search_by(|click_range| { + click_range.cmp(&range, &snapshot.buffer_snapshot) + }) { + click_ranges.insert(idx, range) + } + } + }); + let click_ranges = self.clone_click_ranges::(); + self.highlight_background::( + click_ranges, + |theme| theme.editor.document_highlight_write_background, + cx, + ); + } + pub fn unfold_ranges( &mut self, ranges: impl IntoIterator>,