Scroll back to the left edge when jumping to another file of a diff

Going to the next or previous file of a diff, or picking one from the
jump-to-file menu or the diffstat, brings that file to the top of the
view. The user goes there to read the file from its start, so scroll the
view back to the left edge as well. Jumps between the hunks of a diff
keep the horizontal scroll position, as moving the selection does.

Nothing scrolls the main view horizontally yet, so this changes nothing
on its own. It prepares for scrolling the focused main view sideways
with H and L.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Stefan Haller
2026-10-10 13:44:43 +02:00
co-authored by Claude Opus 5.5
parent 6da4f658d7
commit 2abe4848f3
@@ -75,6 +75,10 @@ func (self *DiffLineHelper) EstablishSelection(mainContext *context.MainContext,
// the first change block at or below the target, which a large context size can put
// further down than a screenful; the selection is then scrolled into view as any other
// jump's is, and the alignment gives way to that.
//
// A jump that aligns its target to the top also scrolls the view back to the left
// edge, whether or not the target is on screen already. Such a jump goes to a file, and
// the user goes there to read the file from its start.
func (self *DiffLineHelper) PlaceNavigationTarget(
pane types.DiffPaneContext, target int, alignTop bool,
) {
@@ -84,6 +88,7 @@ func (self *DiffLineHelper) PlaceNavigationTarget(
return
}
if alignTop {
view.SetOriginX(0)
self.scrollTargetToTop(pane, target)
}
// Jumping to another block or file moves the cursor without shift held, so a