1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-08-24 19:39:16 +02:00

Allow filtered lists to preprocess the filter string

An example for this can be seen in the next commit.

We make this a setter rather than an added constructor argument so that we don't
have to change all those contexts that don't want to make use of this.
This commit is contained in:
Stefan Haller
2025-08-05 15:15:14 +02:00
parent f1c07b3aed
commit d52d5e6a9e

View File

@@ -14,6 +14,7 @@ type FilteredList[T any] struct {
getList func() []T
getFilterFields func(T) []string
preprocessFilter func(string) string
filter string
mutex deadlock.Mutex
@@ -26,6 +27,10 @@ func NewFilteredList[T any](getList func() []T, getFilterFields func(T) []string
}
}
func (self *FilteredList[T]) SetPreprocessFilterFunc(preprocessFilter func(string) string) {
self.preprocessFilter = preprocessFilter
}
func (self *FilteredList[T]) GetFilter() string {
return self.filter
}
@@ -79,7 +84,12 @@ func (self *FilteredList[T]) applyFilter(useFuzzySearch bool) {
self.mutex.Lock()
defer self.mutex.Unlock()
if self.filter == "" {
filter := self.filter
if self.preprocessFilter != nil {
filter = self.preprocessFilter(filter)
}
if filter == "" {
self.filteredIndices = nil
} else {
source := &fuzzySource[T]{
@@ -87,7 +97,7 @@ func (self *FilteredList[T]) applyFilter(useFuzzySearch bool) {
getFilterFields: self.getFilterFields,
}
matches := utils.FindFrom(self.filter, source, useFuzzySearch)
matches := utils.FindFrom(filter, source, useFuzzySearch)
self.filteredIndices = lo.Map(matches, func(match fuzzy.Match, _ int) int {
return match.Index
})