From ba25e371bec1a42f09c4053cf9850417344ec6cd Mon Sep 17 00:00:00 2001 From: Andrew Lygin Date: Fri, 10 May 2024 00:23:21 +0300 Subject: [PATCH] Fix scrollbar markers for folded code (#11625) There're two errors in scrollbar markers in the presence of folded code: 1. Some markers are not displayed (when the marked row numbers are greater than the total displayed rows count after folding). 2. Code folding / unfolding doesn't trigger markers repainting. This PR fixes both problems. Release Notes: - Fixed scrollbar markers for folded code. The second problem (markers are repainted after I move the cursor, not after folding): https://github.com/zed-industries/zed/assets/2101250/57ed563d-186d-4497-98ab-d4f946416726 --- crates/editor/src/editor.rs | 3 +++ crates/editor/src/element.rs | 10 ++-------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 7e7b3dcd97adca649f8e585c55446a20adb2c9a2..bd7ea1988ce46e0e86a50946a074200361316cc2 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -9225,6 +9225,8 @@ impl Editor { self.active_diagnostics = Some(active_diagnostics); } } + + self.scrollbar_marker_state.dirty = true; } } @@ -9258,6 +9260,7 @@ impl Editor { } cx.notify(); + self.scrollbar_marker_state.dirty = true; } } diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 052c40a6dd0eccc0323bad2a90d25e4b0d9ba3fa..9b04445e074035697f663aebab7ef10d41830f7c 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -2866,7 +2866,6 @@ impl EditorElement { let snapshot = layout.position_map.snapshot.clone(); let theme = cx.theme().clone(); let scrollbar_settings = EditorSettings::get_global(cx).scrollbar; - let max_row = layout.max_row; editor.scrollbar_marker_state.dirty = false; editor.scrollbar_marker_state.pending_refresh = @@ -2875,12 +2874,12 @@ impl EditorElement { let scrollbar_markers = cx .background_executor() .spawn(async move { + let max_point = snapshot.display_snapshot.buffer_snapshot.max_point(); let mut marker_quads = Vec::new(); - if scrollbar_settings.git_diff { let marker_row_ranges = snapshot .buffer_snapshot - .git_diff_hunks_in_range(0..max_row) + .git_diff_hunks_in_range(0..max_point.row) .map(|hunk| { let start_display_row = Point::new(hunk.associated_range.start, 0) @@ -2949,9 +2948,6 @@ impl EditorElement { } if scrollbar_settings.diagnostics { - let max_point = - snapshot.display_snapshot.buffer_snapshot.max_point(); - let diagnostics = snapshot .buffer_snapshot .diagnostics_in_range::<_, Point>( @@ -4157,7 +4153,6 @@ impl Element for EditorElement { gutter_dimensions, content_origin, scrollbar_layout, - max_row, active_rows, highlighted_rows, highlighted_ranges, @@ -4290,7 +4285,6 @@ pub struct EditorLayout { cursors: Vec<(DisplayPoint, Hsla)>, visible_cursors: Vec, selections: Vec<(PlayerColor, Vec)>, - max_row: u32, code_actions_indicator: Option, test_indicators: Vec, fold_indicators: Vec>,