mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-30 03:23:08 +03:00
Add search history
Add search history for filterable and searchable views.
This commit is contained in:
@ -3,13 +3,15 @@ package context
|
||||
type FilteredListViewModel[T any] struct {
|
||||
*FilteredList[T]
|
||||
*ListViewModel[T]
|
||||
*SearchHistory
|
||||
}
|
||||
|
||||
func NewFilteredListViewModel[T any](getList func() []T, getFilterFields func(T) []string) *FilteredListViewModel[T] {
|
||||
filteredList := NewFilteredList(getList, getFilterFields)
|
||||
|
||||
self := &FilteredListViewModel[T]{
|
||||
FilteredList: filteredList,
|
||||
FilteredList: filteredList,
|
||||
SearchHistory: NewSearchHistory(),
|
||||
}
|
||||
|
||||
listViewModel := NewListViewModel(filteredList.GetFilteredList)
|
||||
|
20
pkg/gui/context/history_trait.go
Normal file
20
pkg/gui/context/history_trait.go
Normal file
@ -0,0 +1,20 @@
|
||||
package context
|
||||
|
||||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
)
|
||||
|
||||
// Maintains a list of strings that have previously been searched/filtered for
|
||||
type SearchHistory struct {
|
||||
history *utils.HistoryBuffer[string]
|
||||
}
|
||||
|
||||
func NewSearchHistory() *SearchHistory {
|
||||
return &SearchHistory{
|
||||
history: utils.NewHistoryBuffer[string](1000),
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SearchHistory) GetSearchHistory() *utils.HistoryBuffer[string] {
|
||||
return self.history
|
||||
}
|
@ -9,6 +9,7 @@ import (
|
||||
type RemotesContext struct {
|
||||
*FilteredListViewModel[*models.Remote]
|
||||
*ListContextTrait
|
||||
*SearchHistory
|
||||
}
|
||||
|
||||
var (
|
||||
|
@ -9,12 +9,16 @@ import (
|
||||
|
||||
type SearchTrait struct {
|
||||
c *ContextCommon
|
||||
*SearchHistory
|
||||
|
||||
searchString string
|
||||
}
|
||||
|
||||
func NewSearchTrait(c *ContextCommon) *SearchTrait {
|
||||
return &SearchTrait{c: c}
|
||||
return &SearchTrait{
|
||||
c: c,
|
||||
SearchHistory: NewSearchHistory(),
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SearchTrait) GetSearchString() string {
|
||||
|
Reference in New Issue
Block a user