1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-20 05:19:24 +02:00

Call getDisplayStrings with a valid range of model indices

It's nicer if clients can rely on the indices being valid, and don't have to
clamp themselves.
This commit is contained in:
Stefan Haller 2023-08-18 16:50:07 +02:00
parent 473d989cde
commit 297a020abf
3 changed files with 8 additions and 9 deletions

View File

@ -63,7 +63,7 @@ func (self *ListContextTrait) renderLines(startIdx int, endIdx int) string {
columnAlignments = self.getColumnAlignments()
}
return utils.RenderDisplayStrings(
self.getDisplayStrings(startIdx, endIdx),
self.getDisplayStrings(startIdx, utils.Min(endIdx, self.list.Len())),
columnAlignments)
}

View File

@ -68,11 +68,10 @@ func GetCommitListDisplayStrings(
return nil
}
end := utils.Min(endIdx, len(commits))
// this is where my non-TODO commits begin
rebaseOffset := utils.Min(indexOfFirstNonTODOCommit(commits), end)
rebaseOffset := utils.Min(indexOfFirstNonTODOCommit(commits), endIdx)
filteredCommits := commits[startIdx:end]
filteredCommits := commits[startIdx:endIdx]
bisectBounds := getbisectBounds(commits, bisectInfo)
@ -85,8 +84,8 @@ func GetCommitListDisplayStrings(
pipeSets := loadPipesets(commits[rebaseOffset:])
pipeSetOffset := utils.Max(startIdx-rebaseOffset, 0)
graphPipeSets := pipeSets[pipeSetOffset:utils.Max(end-rebaseOffset, 0)]
graphCommits := commits[graphOffset:end]
graphPipeSets := pipeSets[pipeSetOffset:utils.Max(endIdx-rebaseOffset, 0)]
graphCommits := commits[graphOffset:endIdx]
graphLines := graph.RenderAux(
graphPipeSets,
graphCommits,

View File

@ -247,7 +247,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
{Name: "commit5", Sha: "sha5", Parents: []string{"sha7"}},
},
startIdx: 1,
endIdx: 11,
endIdx: 5,
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](),
@ -312,7 +312,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
{Name: "commit5", Sha: "sha5", Parents: []string{"sha7"}},
},
startIdx: 4,
endIdx: 6,
endIdx: 5,
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](),
@ -351,7 +351,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
{Name: "commit3", Sha: "sha3", Parents: []string{"sha4"}},
},
startIdx: 0,
endIdx: 5,
endIdx: 3,
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](),