Attempted to initialize code-fold indicators, does not work

This commit is contained in:
Mikayla Maki 2023-03-02 19:42:59 -08:00
parent 2e1adb0724
commit 3dd5b3f426
2 changed files with 37 additions and 16 deletions

View file

@ -643,7 +643,6 @@ impl DisplaySnapshot {
break;
}
}
let end = end.unwrap_or(max_point);
Some(start..end)
} else {

View file

@ -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>>,