From e783142528cabc9041ae16c33601b5b122c848e8 Mon Sep 17 00:00:00 2001 From: Massimo Mund Date: Fri, 9 Aug 2024 09:35:57 +0200 Subject: [PATCH] Fix `vertical_scroll_margin` not being capped for large `vertical_scroll_margin` values (#15473) When switching to function definitions in a new buffer the `AutoscrollStrategy::Focused` being emitted to scroll to the found location. If a large value `vertical_scroll_margin` (e.g.: 99) is set, this leads to an incorrectly calculated position and the new buffer opens in the wrong place. In `autoscroll_vertically()` there is a margin calculated to cap the value of `vertical_scroll_margin` for certain AutoscrollStrategies. This margin is being used in `AutoscrollStrategy::Fit` and `AutoscrollStrategy::Newest` but was probably forgotten for `AutoscrollStrategy::Focused`. - Might fix [#15101](https://github.com/zed-industries/zed/issues/15101) Release Notes: - N/A --- crates/editor/src/scroll/autoscroll.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/editor/src/scroll/autoscroll.rs b/crates/editor/src/scroll/autoscroll.rs index b5e220bc74efac209fe0c303763db367fd7d85ec..a69b4a11b745399198acd5076c16ab94bb569015 100644 --- a/crates/editor/src/scroll/autoscroll.rs +++ b/crates/editor/src/scroll/autoscroll.rs @@ -189,8 +189,8 @@ impl Editor { self.set_scroll_position_internal(scroll_position, local, true, cx); } AutoscrollStrategy::Focused => { - scroll_position.y = - (target_top - self.scroll_manager.vertical_scroll_margin).max(0.0); + let margin = margin.min(self.scroll_manager.vertical_scroll_margin); + scroll_position.y = (target_top - margin).max(0.0); self.set_scroll_position_internal(scroll_position, local, true, cx); } AutoscrollStrategy::Top => {