mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 12:25:47 +02:00
Support case sensitive filtering
This commit is contained in:
parent
9df634f13f
commit
7d7399a89f
2 changed files with 23 additions and 4 deletions
|
@ -66,7 +66,7 @@ func (self *FilteredList[T]) applyFilter() {
|
|||
}
|
||||
|
||||
func (self *FilteredList[T]) match(haystack string, needle string) bool {
|
||||
return utils.CaseInsensitiveContains(haystack, needle)
|
||||
return utils.CaseAwareContains(haystack, needle)
|
||||
}
|
||||
|
||||
func (self *FilteredList[T]) UnfilteredIndex(index int) int {
|
||||
|
|
|
@ -21,9 +21,28 @@ func FuzzySearch(needle string, haystack []string) []string {
|
|||
})
|
||||
}
|
||||
|
||||
func CaseInsensitiveContains(a, b string) bool {
|
||||
func CaseAwareContains(haystack, needle string) bool {
|
||||
// if needle contains an uppercase letter, we'll do a case sensitive search
|
||||
if ContainsUppercase(needle) {
|
||||
return strings.Contains(haystack, needle)
|
||||
}
|
||||
|
||||
return CaseInsensitiveContains(haystack, needle)
|
||||
}
|
||||
|
||||
func ContainsUppercase(s string) bool {
|
||||
for _, r := range s {
|
||||
if r >= 'A' && r <= 'Z' {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func CaseInsensitiveContains(haystack, needle string) bool {
|
||||
return strings.Contains(
|
||||
strings.ToLower(a),
|
||||
strings.ToLower(b),
|
||||
strings.ToLower(haystack),
|
||||
strings.ToLower(needle),
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue