mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-11-13 08:13:32 -04:00
Don't let "go to bottom" in the commits panel go up
The command went to the commit above the first merged one whenever the commit below the selection wasn't merged. It did this even if the selection was below that commit already. Collect the places where the command can stop, and go to the closest one below the selection, or to the bottom if there is none. This also makes it easy to add more places to stop at. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
381c532b14
commit
7426d7f934
@@ -6,18 +6,33 @@ import (
|
||||
)
|
||||
|
||||
// Returns the index of the commit that the "go to bottom" command selects in a
|
||||
// list of commits
|
||||
// list of commits. If the list has several sections, the command first goes to
|
||||
// the beginning of the section that the selection is in, which is its oldest
|
||||
// commit. From there it goes to the beginning of the next section, and from the
|
||||
// last section to the bottom of the list.
|
||||
//
|
||||
// The sections are:
|
||||
// - the commits of the branch that aren't merged into a main branch yet
|
||||
func indexForGotoBottomInCommits(commits []*models.Commit, selectedIdx int) int {
|
||||
if selectedIdx >= 0 && selectedIdx < len(commits)-1 {
|
||||
if commits[selectedIdx+1].Status != models.StatusMerged {
|
||||
_, idx, found := lo.FindIndexOf(commits, func(c *models.Commit) bool {
|
||||
return c.Status == models.StatusMerged
|
||||
})
|
||||
if found {
|
||||
return idx - 1
|
||||
}
|
||||
}
|
||||
stops := []int{}
|
||||
|
||||
if _, idx, found := lo.FindIndexOf(commits, func(c *models.Commit) bool {
|
||||
return c.Status == models.StatusMerged
|
||||
}); found {
|
||||
stops = append(stops, idx-1)
|
||||
}
|
||||
|
||||
return len(commits) - 1
|
||||
return closestStopBelow(stops, selectedIdx, len(commits)-1)
|
||||
}
|
||||
|
||||
// Returns the smallest of the given stops that is greater than the selected
|
||||
// index, or the last index if there is none
|
||||
func closestStopBelow(stops []int, selectedIdx int, lastIdx int) int {
|
||||
result := lastIdx
|
||||
for _, stop := range stops {
|
||||
if stop > selectedIdx && stop < result {
|
||||
result = stop
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -75,10 +75,7 @@ func TestIndexForGotoBottomInCommits(t *testing.T) {
|
||||
commit("c1", models.StatusUnpushed),
|
||||
commit("m1", models.StatusMerged),
|
||||
},
|
||||
/* EXPECTED:
|
||||
expected: 4,
|
||||
ACTUAL: */
|
||||
expected: 0,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user