diff --git a/src/textual/geometry.py b/src/textual/geometry.py index 59b37b1dd2..3d21f17719 100644 --- a/src/textual/geometry.py +++ b/src/textual/geometry.py @@ -426,7 +426,7 @@ def get_scroll_to_visible( ) if top: - delta_y = top_ - window_top + 1 + delta_y = top_ - window_top elif not ( (window_bottom > top_ >= window_top) diff --git a/src/textual/widget.py b/src/textual/widget.py index d7be2a6442..e1fa1346fc 100644 --- a/src/textual/widget.py +++ b/src/textual/widget.py @@ -2675,7 +2675,7 @@ def scroll_to_widget( else: scroll_offset = container.scroll_to_region( region, - spacing=widget.gutter + widget.dock_gutter, + spacing=widget.dock_gutter, animate=animate, speed=speed, duration=duration, @@ -2745,7 +2745,7 @@ def scroll_to_region( """ window = self.scrollable_content_region.at_offset(self.scroll_offset) if spacing is not None: - region = region.grow(spacing) + window = window.shrink(spacing) if window in region and not (top or center): return Offset() @@ -2762,15 +2762,14 @@ def clamp_delta(delta: Offset) -> Offset: if center: region_center_x, region_center_y = region.center window_center_x, window_center_y = window.center + delta = clamp_delta( Offset( round(region_center_x - window_center_x), round(region_center_y - window_center_y), ) ) - if origin_visible and ( - region.shrink(spacing).offset not in window.translate(delta) - ): + if origin_visible and (region.offset not in window.translate(delta)): delta = clamp_delta( Region.get_scroll_to_visible(window, region, top=True) )