From 1d67763b7eddb05a3a7269e16d71abaa54c2abb8 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 19 Sep 2026 09:48:51 +0200 Subject: [PATCH] Reserve the width the whole reflog needs for its date column Pad the date of every line to the width that the oldest entry in the reflog asks for, so that the column keeps its width as the user scrolls. This is the same treatment the commits panel's date column gets, with the same limits; getReservedColumnWidths spells them out. Co-Authored-By: Claude Opus 5 (1M context) --- pkg/gui/presentation/reflog_commits.go | 26 +++++++++++++++------ pkg/gui/presentation/reflog_commits_test.go | 5 ---- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/pkg/gui/presentation/reflog_commits.go b/pkg/gui/presentation/reflog_commits.go index 785776864..50305b1d3 100644 --- a/pkg/gui/presentation/reflog_commits.go +++ b/pkg/gui/presentation/reflog_commits.go @@ -18,8 +18,13 @@ func GetReflogCommitListDisplayStrings(commits []*models.Commit, startIdx int, e } var displayFunc func(*models.Commit, reflogCommitDisplayAttributes) []string + reservedDateWidth := 0 if fullDescription { displayFunc = getFullDescriptionDisplayStringsForReflogCommit + // See getReservedColumnWidths for why the oldest entry alone decides + // how much width the date column needs. + reservedDateWidth = utils.StringWidth(utils.UnixToDateSmart( + now, commits[len(commits)-1].UnixTimestamp, timeFormat, shortTimeFormat)) } else { displayFunc = getDisplayStringsForReflogCommit } @@ -29,12 +34,13 @@ func GetReflogCommitListDisplayStrings(commits []*models.Commit, startIdx int, e cherryPicked := cherryPickedCommitHashSet.Includes(commit.Hash()) return displayFunc(commit, reflogCommitDisplayAttributes{ - cherryPicked: cherryPicked, - diffed: diffed, - parseEmoji: parseEmoji, - timeFormat: timeFormat, - shortTimeFormat: shortTimeFormat, - now: now, + cherryPicked: cherryPicked, + diffed: diffed, + parseEmoji: parseEmoji, + timeFormat: timeFormat, + shortTimeFormat: shortTimeFormat, + now: now, + reservedDateWidth: reservedDateWidth, }) }) } @@ -59,6 +65,9 @@ type reflogCommitDisplayAttributes struct { timeFormat string shortTimeFormat string now time.Time + // The width the date column needs for the whole reflog, not just for the + // lines that are on screen + reservedDateWidth int } func getFullDescriptionDisplayStringsForReflogCommit(c *models.Commit, attrs reflogCommitDisplayAttributes) []string { @@ -67,9 +76,12 @@ func getFullDescriptionDisplayStringsForReflogCommit(c *models.Commit, attrs ref name = emoji.Sprint(name) } + date := style.FgMagenta.Sprint( + utils.UnixToDateSmart(attrs.now, c.UnixTimestamp, attrs.timeFormat, attrs.shortTimeFormat)) + return []string{ reflogHashColor(attrs.cherryPicked, attrs.diffed).Sprint(c.ShortHash()), - style.FgMagenta.Sprint(utils.UnixToDateSmart(attrs.now, c.UnixTimestamp, attrs.timeFormat, attrs.shortTimeFormat)), + utils.WithPadding(date, attrs.reservedDateWidth, utils.AlignLeft), theme.DefaultTextColor.Sprint(name), } } diff --git a/pkg/gui/presentation/reflog_commits_test.go b/pkg/gui/presentation/reflog_commits_test.go index ead3212e4..9a81a7021 100644 --- a/pkg/gui/presentation/reflog_commits_test.go +++ b/pkg/gui/presentation/reflog_commits_test.go @@ -77,14 +77,9 @@ func TestGetReflogCommitListDisplayStrings(t *testing.T) { startIdx: 0, endIdx: 1, now: time.Date(2020, 1, 1, 5, 3, 4, 0, time.UTC), - /* EXPECTED: expected: formatExpected(` hash1 2:03AM commit: today `), - ACTUAL: */ - expected: formatExpected(` - hash1 2:03AM commit: today - `), }, }