Skip to content

Commit 99b952c

Browse files
committed
Search viewLines rather than lines
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.
1 parent bb2e36a commit 99b952c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

view.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,8 @@ func (v *View) updateSearchPositions() {
10871087

10881088
if v.searcher.modelSearchResults != nil {
10891089
for _, result := range v.searcher.modelSearchResults {
1090+
// This code only works when v.Wrap is false.
1091+
10901092
if result.Y >= len(v.lines) {
10911093
break
10921094
}
@@ -1115,8 +1117,9 @@ func (v *View) updateSearchPositions() {
11151117
}
11161118
}
11171119
} else {
1118-
for y, line := range v.lines {
1119-
v.searcher.searchPositions = append(v.searcher.searchPositions, searchPositionsForLine(line, y)...)
1120+
v.refreshViewLinesIfNeeded()
1121+
for y, line := range v.viewLines {
1122+
v.searcher.searchPositions = append(v.searcher.searchPositions, searchPositionsForLine(line.line, y)...)
11201123
}
11211124
}
11221125
}

0 commit comments

Comments
 (0)