From d198ce56f120ec0b52a4eb9388946422f28e6aa3 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Tue, 13 Oct 2026 16:23:36 +0200 Subject: [PATCH] Extract how far a jump can scroll its target to the top of the view A jump in a pane that isn't focused is going to stop at the last screenful of the diff as well. Co-Authored-By: Claude Opus 5.5 (1M context) --- .../controllers/helpers/diff_line_selection.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pkg/gui/controllers/helpers/diff_line_selection.go b/pkg/gui/controllers/helpers/diff_line_selection.go index 4d6b26b51..4cc86d5b8 100644 --- a/pkg/gui/controllers/helpers/diff_line_selection.go +++ b/pkg/gui/controllers/helpers/diff_line_selection.go @@ -106,16 +106,21 @@ func (self *DiffLineHelper) PlaceNavigationTarget( } // scrollTargetToTop scrolls the given row of the diff to the top of the view, leaving -// the view where it is when that row is on screen already. The last screenful of the -// diff is as far as it goes, so that the view doesn't scroll past the end of what it is -// showing. +// the view where it is when that row is on screen already. func (self *DiffLineHelper) scrollTargetToTop(pane types.DiffPaneContext, target int) { - view := pane.GetView() originY, height := pane.GetViewTrait().ViewPortYBounds() if target >= originY && target < originY+height { return } - view.SetOriginY(min(target, max(0, view.ViewLinesHeight()-height))) + pane.GetView().SetOriginY(originYWithTargetAtTop(pane, target)) +} + +// originYWithTargetAtTop returns the origin that puts the given row of the diff at the +// top of the view. The last screenful of the diff is as far as it goes, so that the +// view doesn't scroll past the end of what it is showing. +func originYWithTargetAtTop(pane types.DiffPaneContext, target int) int { + _, height := pane.GetViewTrait().ViewPortYBounds() + return min(target, max(0, pane.GetView().ViewLinesHeight()-height)) } // CollapseNonStickyRange drops a range that only grows while shift is held back to a