From af87cd1dd6e58e9472353d783b7c148d925c7a05 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Fri, 9 Aug 2024 14:51:01 +0200 Subject: [PATCH] Don't return model search results for commits when we don't have columnPositions We fixed one specific scenario where this happened ealier in this branch, but in case there are more that we don't know about yet, at least make sure we don't crash. --- pkg/gui/context/local_commits_context.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/gui/context/local_commits_context.go b/pkg/gui/context/local_commits_context.go index 0cb7a628c..eecb16107 100644 --- a/pkg/gui/context/local_commits_context.go +++ b/pkg/gui/context/local_commits_context.go @@ -202,6 +202,15 @@ func shouldShowGraph(c *ContextCommon) bool { } func searchModelCommits(caseSensitive bool, commits []*models.Commit, columnPositions []int, searchStr string) []gocui.SearchPosition { + if columnPositions == nil { + // This should never happen. We are being called at a time where our + // entire view content is scrolled out of view, so that we didn't draw + // anything the last time we rendered. If we run into a scenario where + // this happens, we should fix it, but until we found them all, at least + // make sure we don't crash. + return []gocui.SearchPosition{} + } + normalize := lo.Ternary(caseSensitive, func(s string) string { return s }, strings.ToLower) return lo.FilterMap(commits, func(commit *models.Commit, idx int) (gocui.SearchPosition, bool) { // The XStart and XEnd values are only used if the search string can't