Skip to content

Commit 2b41a27

Browse files
committed
Fix search results being off by two lines during rebase or in divergence view
We forgot to convert the model indices to view indices in searchModelCommits. This needs to be done for search results to be highlighted correctly in the "divergence from upstream" view, which adds "--- Remote/Local ---" entries, and during a rebase, where we have "--- Pending rebase todos ---" and "--- Commits ---" which offset view indices from model indices.
1 parent dd47ef7 commit 2b41a27

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

pkg/gui/context/local_commits_context.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ func (self *LocalCommitsContext) RefForAdjustingLineNumberInDiff() string {
223223
}
224224

225225
func (self *LocalCommitsContext) ModelSearchResults(searchStr string, caseSensitive bool) []gocui.SearchPosition {
226-
return searchModelCommits(caseSensitive, self.GetCommits(), self.ColumnPositions(), searchStr)
226+
return searchModelCommits(caseSensitive, self.GetCommits(), self.ColumnPositions(), self.ModelIndexToViewIndex, searchStr)
227227
}
228228

229229
func (self *LocalCommitsViewModel) SetLimitCommits(value bool) {
@@ -266,7 +266,9 @@ func shouldShowGraph(c *ContextCommon) bool {
266266
return false
267267
}
268268

269-
func searchModelCommits(caseSensitive bool, commits []*models.Commit, columnPositions []int, searchStr string) []gocui.SearchPosition {
269+
func searchModelCommits(caseSensitive bool, commits []*models.Commit, columnPositions []int,
270+
modelToViewIndex func(int) int, searchStr string,
271+
) []gocui.SearchPosition {
270272
if columnPositions == nil {
271273
// This should never happen. We are being called at a time where our
272274
// entire view content is scrolled out of view, so that we didn't draw
@@ -283,7 +285,7 @@ func searchModelCommits(caseSensitive bool, commits []*models.Commit, columnPosi
283285
// searching for a commit hash that is longer than the truncated hash
284286
// that we render. So we just set the XStart and XEnd values to the
285287
// start and end of the commit hash column, which is the second one.
286-
result := gocui.SearchPosition{XStart: columnPositions[1], XEnd: columnPositions[2] - 1, Y: idx}
288+
result := gocui.SearchPosition{XStart: columnPositions[1], XEnd: columnPositions[2] - 1, Y: modelToViewIndex(idx)}
287289
return result, strings.Contains(normalize(commit.Hash()), searchStr) ||
288290
strings.Contains(normalize(commit.Name), searchStr) ||
289291
strings.Contains(normalize(commit.ExtraInfo), searchStr) // allow searching for tags

pkg/gui/context/sub_commits_context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func (self *SubCommitsContext) RefForAdjustingLineNumberInDiff() string {
225225
}
226226

227227
func (self *SubCommitsContext) ModelSearchResults(searchStr string, caseSensitive bool) []gocui.SearchPosition {
228-
return searchModelCommits(caseSensitive, self.GetCommits(), self.ColumnPositions(), searchStr)
228+
return searchModelCommits(caseSensitive, self.GetCommits(), self.ColumnPositions(), self.ModelIndexToViewIndex, searchStr)
229229
}
230230

231231
func (self *SubCommitsContext) IndexForGotoBottom() int {

0 commit comments

Comments
 (0)