Makes search insensitive

This commit is contained in:
sloum 2020-03-17 05:19:26 +00:00
parent d17e530667
commit cb55293bdb
1 changed files with 8 additions and 4 deletions

12
page.go
View File

@ -123,8 +123,9 @@ func (p *Page) HighlightFoundText() {
if p.SearchTerm == "" {
return
}
lowS := strings.ToLower(p.SearchTerm)
for i, ln := range p.WrappedContent {
found := strings.Index(ln, p.SearchTerm)
found := strings.Index(strings.ToLower(ln), lowS)
if found < 0 {
continue
}
@ -132,7 +133,8 @@ func (p *Page) HighlightFoundText() {
if bombadillo.Options["theme"] == "inverse" {
format = "\033[27m%s\033[7m"
}
ln = strings.Replace(ln, p.SearchTerm, fmt.Sprintf(format, p.SearchTerm), -1)
foundS := ln[found:found+len(lowS)]
ln = strings.Replace(ln, foundS, fmt.Sprintf(format, foundS), -1)
p.WrappedContent[i] = ln
}
}
@ -148,12 +150,14 @@ func (p *Page) FindText() {
if bombadillo.Options["theme"] == "inverse" {
format = "\033[27m%s\033[7m"
}
lowS := strings.ToLower(s)
for i, ln := range p.WrappedContent {
found := strings.Index(ln, s)
found := strings.Index(strings.ToLower(ln), lowS)
if found < 0 {
continue
}
ln = strings.Replace(ln, s, fmt.Sprintf(format, s), -1)
foundS := ln[found:found+len(lowS)]
ln = strings.Replace(ln, foundS, fmt.Sprintf(format, foundS), -1)
p.WrappedContent[i] = ln
p.FoundLinkLines = append(p.FoundLinkLines, i)
}