Attempted to initialize code-fold indicators, does not work

Mikayla Maki created

Change summary

crates/editor/src/display_map.rs |  1 
crates/editor/src/editor.rs      | 52 ++++++++++++++++++++++++---------
2 files changed, 37 insertions(+), 16 deletions(-)

Detailed changes

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::<FoldMarker>(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::<FoldMarker>();
-            self.highlight_background::<FoldMarker>(
-                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<Item = Range<Anchor>>,
+        snapshot: &EditorSnapshot,
+        cx: &mut ViewContext<Editor>,
+    ) {
+        self.change_click_ranges::<FoldMarker>(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::<FoldMarker>();
+        self.highlight_background::<FoldMarker>(
+            click_ranges,
+            |theme| theme.editor.document_highlight_write_background,
+            cx,
+        );
+    }
+
     pub fn unfold_ranges<T: ToOffset + Clone>(
         &mut self,
         ranges: impl IntoIterator<Item = Range<T>>,