diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-03-09 11:10:54 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-03-09 11:17:50 +1100 |
commit | 8f68ac21293f1a0476802974817d9f87875f8743 (patch) | |
tree | 15aae04262e39f1197fdc0a7a28a3464b2ef270c /vendor | |
parent | 1ea2825a54ce202144114e5dcf4a97282203ee67 (diff) |
case insensitive search
By default, search is now case insensitive.
If you include uppercase characters in your search string, the search
will become case sensitive. This means there is no way to do a case-
insensitive search of all-lowercase strings. We could add more support
for this but we'll wait until we come across the use case
Diffstat (limited to 'vendor')
-rw-r--r-- | vendor/github.com/jesseduffield/gocui/view.go | 27 | ||||
-rw-r--r-- | vendor/modules.txt | 2 |
2 files changed, 25 insertions, 4 deletions
diff --git a/vendor/github.com/jesseduffield/gocui/view.go b/vendor/github.com/jesseduffield/gocui/view.go index fb3b1e54d..77738f24f 100644 --- a/vendor/github.com/jesseduffield/gocui/view.go +++ b/vendor/github.com/jesseduffield/gocui/view.go @@ -10,6 +10,7 @@ import ( "strings" "sync" "time" + "unicode" "github.com/go-errors/errors" @@ -466,18 +467,38 @@ func (v *View) Rewind() { v.readOffset = 0 } +func containsUpcaseChar(str string) bool { + for _, ch := range str { + if unicode.IsUpper(ch) { + return true + } + } + return false +} + func (v *View) updateSearchPositions() { if v.searcher.searchString != "" { + var normalizeRune func(r rune) rune + var normalizedSearchStr string + // if we have any uppercase characters we'll do a case-sensitive search + if containsUpcaseChar(v.searcher.searchString) { + normalizedSearchStr = v.searcher.searchString + normalizeRune = func(r rune) rune { return r } + } else { + normalizedSearchStr = strings.ToLower(v.searcher.searchString) + normalizeRune = unicode.ToLower + } + v.searcher.searchPositions = []cellPos{} for y, line := range v.lines { lineLoop: for x, _ := range line { - if line[x].chr == rune(v.searcher.searchString[0]) { - for offset := 1; offset < len(v.searcher.searchString); offset++ { + if normalizeRune(line[x].chr) == rune(normalizedSearchStr[0]) { + for offset := 1; offset < len(normalizedSearchStr); offset++ { if len(line)-1 < x+offset { continue lineLoop } - if line[x+offset].chr != rune(v.searcher.searchString[offset]) { + if normalizeRune(line[x+offset].chr) != rune(normalizedSearchStr[offset]) { continue lineLoop } } diff --git a/vendor/modules.txt b/vendor/modules.txt index 26eaf67e5..a098e0700 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -42,7 +42,7 @@ github.com/hashicorp/hcl/json/token github.com/integrii/flaggy # github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 github.com/jbenet/go-context/io -# github.com/jesseduffield/gocui v0.3.1-0.20200301081700-d6e485450113 +# github.com/jesseduffield/gocui v0.3.1-0.20200309001002-7765949e1c8a ## explicit github.com/jesseduffield/gocui # github.com/jesseduffield/pty v1.2.1 |