Skip to content

Commit

Permalink
If the match strings overlap, set the same coloring as git grep
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW committed Nov 1, 2021
1 parent 5cd8264 commit 732dc8a
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,26 @@ func Scan(ctx context.Context, fsys fs.FS, w io.Writer, opts *Opts) error {
}

sort.Slice(matches, func(i, j int) bool {
return matches[i][0] > matches[j][0]
return matches[i][0] < matches[j][0]
})

// TODO: refactor
i := 0
f := [][]int{}
for i := range matches {
if i+1 == len(matches) || matches[i][1] < matches[i+1][0] {
for {
if i+1 == len(matches) {
f = append(f, matches[i])
break
} else if i+1 > len(matches) {
break
}
if matches[i][1] < matches[i+1][0] {
f = append(f, matches[i])
} else if matches[i][1] >= matches[i+1][0] {
f = append(f, matches[i])
i += 1
}
i += 1
}
matches = f

Expand Down

0 comments on commit 732dc8a

Please sign in to comment.