Skip to content

Commit

Permalink
Search viewLines rather than lines
Browse files Browse the repository at this point in the history
So far, search was only enabled in views with Wrap=false, so it didn't make a
difference. If Wrap is on, we need to work with viewLines rather than lines,
because that's what the code that highlights the search results expects. Note
that a viewLine index is also passed back to the onSelectItem callback, so
clients need to be able to deal with that.

We don't touch the modelSearchResults code path, as it's a bit unclear how to
support Wrap=true in that case, and we don't need it right now.
  • Loading branch information
stefanhaller committed Dec 2, 2024
1 parent bb2e36a commit 99b952c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions view.go
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,8 @@ func (v *View) updateSearchPositions() {

if v.searcher.modelSearchResults != nil {
for _, result := range v.searcher.modelSearchResults {
// This code only works when v.Wrap is false.

if result.Y >= len(v.lines) {
break
}
Expand Down Expand Up @@ -1115,8 +1117,9 @@ func (v *View) updateSearchPositions() {
}
}
} else {
for y, line := range v.lines {
v.searcher.searchPositions = append(v.searcher.searchPositions, searchPositionsForLine(line, y)...)
v.refreshViewLinesIfNeeded()
for y, line := range v.viewLines {
v.searcher.searchPositions = append(v.searcher.searchPositions, searchPositionsForLine(line.line, y)...)
}
}
}
Expand Down

0 comments on commit 99b952c

Please sign in to comment.