Case insensitive string comparison

This commit is contained in:
Jesse Duffield
2023-05-27 20:38:37 +10:00
parent 13326344f0
commit bf5871cc4f
5 changed files with 97 additions and 57 deletions

View File

@@ -1,8 +1,6 @@
package context
import (
"strings"
"github.com/jesseduffield/lazygit/pkg/utils"
)
@@ -35,6 +33,10 @@ func (self *FilteredList[T]) ClearFilter() {
self.SetFilter("")
}
func (self *FilteredList[T]) IsFiltering() bool {
return self.filter != ""
}
func (self *FilteredList[T]) GetFilteredList() []T {
if self.filteredIndices == nil {
return self.getList()
@@ -54,7 +56,7 @@ func (self *FilteredList[T]) applyFilter() {
self.filteredIndices = []int{}
for i, item := range self.getList() {
for _, field := range self.getFilterFields(item) {
if strings.Contains(field, self.filter) {
if self.match(field, self.filter) {
self.filteredIndices = append(self.filteredIndices, i)
break
}
@@ -62,3 +64,7 @@ func (self *FilteredList[T]) applyFilter() {
}
}
}
func (self *FilteredList[T]) match(haystack string, needle string) bool {
return utils.CaseInsensitiveContains(haystack, needle)
}

View File

@@ -32,7 +32,6 @@ func NewWorkingTreeContext(c *ContextCommon) *WorkingTreeContext {
)
getDisplayStrings := func(startIdx int, length int) [][]string {
c.Log.Warn("in get display strings")
lines := presentation.RenderFileTree(viewModel, c.Modes().Diffing.Ref, c.Model().Submodules)
return slices.Map(lines, func(line string) []string {
return []string{line}