mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-24 23:40:03 -05:00
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) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
7cf7b51467
commit
1d67763b7e
@@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
`),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user