From 8f68ac21293f1a0476802974817d9f87875f8743 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Mon, 9 Mar 2020 11:10:54 +1100 Subject: [PATCH] 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 --- go.mod | 2 +- go.sum | 2 ++ vendor/github.com/jesseduffield/gocui/view.go | 27 ++++++++++++++++--- vendor/modules.txt | 2 +- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index eca4a2d3e..f904807e2 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/golang/protobuf v1.3.2 // indirect github.com/google/go-cmp v0.3.1 // indirect github.com/integrii/flaggy v1.4.0 - github.com/jesseduffield/gocui v0.3.1-0.20200301081700-d6e485450113 + github.com/jesseduffield/gocui v0.3.1-0.20200309001002-7765949e1c8a github.com/jesseduffield/pty v1.2.1 github.com/jesseduffield/termbox-go v0.0.0-20200130214842-1d31d1faa3c9 // indirect github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 diff --git a/go.sum b/go.sum index b9db22d36..20f5183f9 100644 --- a/go.sum +++ b/go.sum @@ -80,6 +80,8 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOl github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jesseduffield/gocui v0.3.1-0.20200301081700-d6e485450113 h1:jHZRVJUWsU8HaQ0crocz0i0BkpOqFLDJEO/AtBp+Ecs= github.com/jesseduffield/gocui v0.3.1-0.20200301081700-d6e485450113/go.mod h1:2RtZznzYKt8RLRwvFiSkXjU0Ei8WwHdubgnlaYH47dw= +github.com/jesseduffield/gocui v0.3.1-0.20200309001002-7765949e1c8a h1:JSORQue6V4bMppr22dtUuYX+w79cgupo66PcGZ9ijlU= +github.com/jesseduffield/gocui v0.3.1-0.20200309001002-7765949e1c8a/go.mod h1:2RtZznzYKt8RLRwvFiSkXjU0Ei8WwHdubgnlaYH47dw= github.com/jesseduffield/pty v1.2.1 h1:7xYBiwNH0PpWqC8JmvrPq1a/ksNqyCavzWu9pbBGYWI= github.com/jesseduffield/pty v1.2.1/go.mod h1:7jlS40+UhOqkZJDIG1B/H21xnuET/+fvbbnHCa8wSIo= github.com/jesseduffield/termbox-go v0.0.0-20200130214842-1d31d1faa3c9 h1:iBBk1lhFwjwJw//J2m1yyz9S368GeXQTpMVACTyQMh0= 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