Unify the "go to bottom" logic of the two commit list contexts

The local commits and the sub-commits contexts had identical copies of
it. We are going to make it smarter, so make sure the copies don't
drift apart.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Stefan Haller
2026-11-08 12:40:28 +01:00
co-authored by Claude Opus 5.5
parent 89c6f0ce5a
commit 97aeaf77a5
3 changed files with 25 additions and 28 deletions
@@ -0,0 +1,23 @@
package context
import (
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/samber/lo"
)
// Returns the index of the commit that the "go to bottom" command selects in a
// list of commits
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
}
}
}
return len(commits) - 1
}
+1 -14
View File
@@ -520,18 +520,5 @@ func searchModelCommits(caseSensitive bool, commits []*models.Commit, columnPosi
}
func (self *LocalCommitsContext) IndexForGotoBottom() int {
commits := self.GetCommits()
selectedIdx := self.GetSelectedLineIdx()
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
}
}
}
return self.list.Len() - 1
return indexForGotoBottomInCommits(self.GetCommits(), self.GetSelectedLineIdx())
}
+1 -14
View File
@@ -269,18 +269,5 @@ func (self *SubCommitsContext) ModelSearchResults(searchStr string, caseSensitiv
}
func (self *SubCommitsContext) IndexForGotoBottom() int {
commits := self.GetCommits()
selectedIdx := self.GetSelectedLineIdx()
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
}
}
}
return self.list.Len() - 1
return indexForGotoBottomInCommits(self.GetCommits(), self.GetSelectedLineIdx())
}