diff --git a/crates/diagnostics/src/diagnostics.rs b/crates/diagnostics/src/diagnostics.rs index 299eed77c1..79391b2d5a 100644 --- a/crates/diagnostics/src/diagnostics.rs +++ b/crates/diagnostics/src/diagnostics.rs @@ -146,8 +146,11 @@ impl ProjectDiagnosticsEditor { let excerpts = cx.add_model(|cx| MultiBuffer::new(project.read(cx).replica_id())); let build_settings = editor::settings_builder(excerpts.downgrade(), settings.clone()); - let editor = - cx.add_view(|cx| Editor::for_buffer(excerpts.clone(), build_settings.clone(), cx)); + let editor = cx.add_view(|cx| { + let mut editor = Editor::for_buffer(excerpts.clone(), build_settings.clone(), cx); + editor.set_vertical_scroll_margin(5, cx); + editor + }); cx.subscribe(&editor, |_, _, event, cx| cx.emit(*event)) .detach(); diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 3f38f82aa7..26d7f2f875 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -379,6 +379,7 @@ pub struct Editor { blink_epoch: usize, blinking_paused: bool, mode: EditorMode, + vertical_scroll_margin: f32, placeholder_text: Option>, highlighted_rows: Option>, nav_history: Option, @@ -518,6 +519,7 @@ impl Editor { blink_epoch: 0, blinking_paused: false, mode: EditorMode::Full, + vertical_scroll_margin: 3.0, placeholder_text: None, highlighted_rows: None, nav_history: None, @@ -591,6 +593,11 @@ impl Editor { cx.notify(); } + pub fn set_vertical_scroll_margin(&mut self, margin_rows: usize, cx: &mut ViewContext) { + self.vertical_scroll_margin = margin_rows as f32; + cx.notify(); + } + pub fn set_scroll_position(&mut self, scroll_position: Vector2F, cx: &mut ViewContext) { let map = self.display_map.update(cx, |map, cx| map.snapshot(cx)); @@ -690,7 +697,7 @@ impl Editor { match autoscroll { Autoscroll::Fit | Autoscroll::Newest => { - let margin = margin.min(3.0); + let margin = margin.min(self.vertical_scroll_margin); let target_top = (first_cursor_top - margin).max(0.0); let target_bottom = last_cursor_bottom + margin; let start_row = scroll_position.y();