From 4f678b7d0d5184e90ded1d866729a61fb1886203 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Fri, 9 Oct 2026 08:44:26 +0200 Subject: [PATCH] Keep the horizontal scroll position when a diff is rendered again Two places that position the main view after a re-render of the same diff call SetOrigin(0, y), although they only mean to move the view vertically. One is the restore after a change of the context size, of whitespace handling or of the diff renderer. The other is the clamp for content that ends above the scroll position, for example after staging a large part of the diff. Use SetOriginY in both, so that they keep the horizontal scroll position. 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) --- pkg/gui/controllers/helpers/diff_line_restore.go | 2 +- pkg/gui/tasks_adapter.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/gui/controllers/helpers/diff_line_restore.go b/pkg/gui/controllers/helpers/diff_line_restore.go index c51bbe31b..5cd924cc9 100644 --- a/pkg/gui/controllers/helpers/diff_line_restore.go +++ b/pkg/gui/controllers/helpers/diff_line_restore.go @@ -81,7 +81,7 @@ func (self *DiffLineHelper) PreserveDiffPositionOnRerender(view *gocui.View) { // Put the line back on the screen row it was on, clamped into the view for // the fallback lines, which can come from off screen. row := lo.Clamp(anchor.row, 0, max(0, view.InnerHeight()-1)) - view.SetOrigin(0, max(0, viewLine-row)) + view.SetOriginY(max(0, viewLine-row)) if showSelection { // Put the far end back before the cursor, so that the selection covers // the same lines again; a selection whose far end didn't survive the diff --git a/pkg/gui/tasks_adapter.go b/pkg/gui/tasks_adapter.go index c2db5f1ec..5b87a9d59 100644 --- a/pkg/gui/tasks_adapter.go +++ b/pkg/gui/tasks_adapter.go @@ -233,7 +233,7 @@ func (gui *Gui) getManager(view *gocui.View) *tasks.ViewBufferManager { if linesHeight < originY { newOriginY := linesHeight - view.SetOrigin(0, newOriginY) + view.SetOriginY(newOriginY) } gui.updateDiffPaneDecorations(view, true)