Skip to content

Commit c4e36ee

Browse files
committed
fixed bug in findUp
1 parent 4f5806e commit c4e36ee

1 file changed

Lines changed: 6 additions & 15 deletions

File tree

internal/buffer/search.go

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -105,30 +105,21 @@ func (b *Buffer) findUp(r *regexp.Regexp, start, end Loc) ([2]Loc, bool) {
105105
}
106106

107107
for i := end.Y; i >= start.Y; i-- {
108-
l, charpos, padMode, rPadded := findLineParams(b, start, end, i, r)
109-
110-
allMatches := rPadded.FindAllIndex(l, -1)
108+
charCount := util.CharacterCount(b.LineBytes(i))
109+
from := Loc{0, i}.Clamp(start, end)
110+
to := Loc{charCount, i}.Clamp(start, end)
111111

112+
allMatches := b.findAll(r, from, to)
112113
if allMatches != nil {
113114
match := allMatches[len(allMatches)-1]
114-
if padMode&padStart != 0 {
115-
_, size := utf8.DecodeRune(l[match[0]:])
116-
match[0] += size
117-
}
118-
if padMode&padEnd != 0 {
119-
_, size := utf8.DecodeLastRune(l[:match[1]])
120-
match[1] -= size
121-
}
122-
start := Loc{charpos + util.RunePos(l, match[0]), i}
123-
end := Loc{charpos + util.RunePos(l, match[1]), i}
124-
return [2]Loc{start, end}, true
115+
return [2]Loc{match[0], match[1]}, true
125116
}
126117
}
127118
return [2]Loc{}, false
128119
}
129120

130121
func (b *Buffer) findAll(r *regexp.Regexp, start, end Loc) [][2]Loc {
131-
matches := [][2]Loc{}
122+
var matches [][2]Loc
132123
loc := start
133124
for {
134125
match, found := b.findDown(r, loc, end)

0 commit comments

Comments
 (0)