Skip to content

Commit 4a77c1f

Browse files
committed
removed start > end tests for new functions
1 parent 1e9e63f commit 4a77c1f

1 file changed

Lines changed: 8 additions & 25 deletions

File tree

internal/buffer/search.go

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,6 @@ func regexpData(re any) (*RegexpData, error) {
5454
type bytesFind func(*regexp.Regexp, []byte) []int
5555

5656
func (b *Buffer) findDownFunc(redata *RegexpData, start, end Loc, find bytesFind) []Loc {
57-
lastcn := util.CharacterCount(b.LineBytes(b.LinesNum() - 1))
58-
if start.Y > b.LinesNum()-1 {
59-
start.X = lastcn - 1
60-
}
61-
if end.Y > b.LinesNum()-1 {
62-
end.X = lastcn
63-
}
64-
start.Y = util.Clamp(start.Y, 0, b.LinesNum()-1)
65-
end.Y = util.Clamp(end.Y, 0, b.LinesNum()-1)
66-
67-
if start.GreaterThan(end) {
68-
start, end = end, start
69-
}
70-
7157
for i := start.Y; i <= end.Y; i++ {
7258
l := b.LineBytes(i)
7359
from, to := 0, len(l)
@@ -135,6 +121,9 @@ func (b *Buffer) FindDown(re string, start, end Loc) ([]Loc, error) {
135121
}
136122

137123
func (b *Buffer) FindRegexpDown(redata *RegexpData, start, end Loc) []Loc {
124+
if start.GreaterThan(end) {
125+
return nil
126+
}
138127
return b.findDownFunc(redata, start, end, (*regexp.Regexp).FindSubmatchIndex)
139128
}
140129

@@ -151,18 +140,8 @@ func (b *Buffer) FindUp(re string, start, end Loc) ([]Loc, error) {
151140
}
152141

153142
func (b *Buffer) FindRegexpUp(redata *RegexpData, start, end Loc) []Loc {
154-
lastcn := util.CharacterCount(b.LineBytes(b.LinesNum() - 1))
155-
if start.Y > b.LinesNum()-1 {
156-
start.X = lastcn - 1
157-
}
158-
if end.Y > b.LinesNum()-1 {
159-
end.X = lastcn
160-
}
161-
start.Y = util.Clamp(start.Y, 0, b.LinesNum()-1)
162-
end.Y = util.Clamp(end.Y, 0, b.LinesNum()-1)
163-
164143
if start.GreaterThan(end) {
165-
start, end = end, start
144+
return nil
166145
}
167146

168147
var locs []Loc
@@ -272,6 +251,10 @@ func (b *Buffer) FindNext(s string, start, end, from Loc, down bool, useRegex bo
272251
return [2]Loc{}, false, err
273252
}
274253

254+
if start.GreaterThan(end) {
255+
start, end = end, start
256+
}
257+
275258
var match []Loc
276259
if down {
277260
match = b.FindRegexpDown(redata, from, end)

0 commit comments

Comments
 (0)