mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 12:25:47 +02:00
Get rid of the retain-sort-order-when-filtering logic again
For die-hard fuzzy-searching fans it's probably in the way, so taking it out makes fuzzy filtering work better. For substring filtering it always retains the sort order anyway.
This commit is contained in:
parent
7d2163d632
commit
4f2bebe453
11 changed files with 13 additions and 29 deletions
|
@ -22,7 +22,6 @@ func NewBranchesContext(c *ContextCommon) *BranchesContext {
|
|||
func(branch *models.Branch) []string {
|
||||
return []string{branch.Name}
|
||||
},
|
||||
func() bool { return c.AppState.LocalBranchSortOrder != "alphabetical" },
|
||||
)
|
||||
|
||||
getDisplayStrings := func(_ int, _ int) [][]string {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package context
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
|
@ -17,21 +16,14 @@ type FilteredList[T any] struct {
|
|||
getFilterFields func(T) []string
|
||||
filter string
|
||||
|
||||
// Normally, filtered items are presented sorted by best match. If this
|
||||
// function returns true, they retain their original sort order instead;
|
||||
// this is useful for lists that show items sorted by date, for example.
|
||||
// Leaving this nil is equivalent to returning false.
|
||||
shouldRetainSortOrder func() bool
|
||||
|
||||
mutex *deadlock.Mutex
|
||||
}
|
||||
|
||||
func NewFilteredList[T any](getList func() []T, getFilterFields func(T) []string, shouldRetainSortOrder func() bool) *FilteredList[T] {
|
||||
func NewFilteredList[T any](getList func() []T, getFilterFields func(T) []string) *FilteredList[T] {
|
||||
return &FilteredList[T]{
|
||||
getList: getList,
|
||||
getFilterFields: getFilterFields,
|
||||
shouldRetainSortOrder: shouldRetainSortOrder,
|
||||
mutex: &deadlock.Mutex{},
|
||||
getList: getList,
|
||||
getFilterFields: getFilterFields,
|
||||
mutex: &deadlock.Mutex{},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,9 +92,6 @@ func (self *FilteredList[T]) applyFilter(useFuzzySearch bool) {
|
|||
self.filteredIndices = lo.Map(matches, func(match fuzzy.Match, _ int) int {
|
||||
return match.Index
|
||||
})
|
||||
if useFuzzySearch && self.shouldRetainSortOrder != nil && self.shouldRetainSortOrder() {
|
||||
slices.Sort(self.filteredIndices)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,8 +6,8 @@ type FilteredListViewModel[T HasID] struct {
|
|||
*SearchHistory
|
||||
}
|
||||
|
||||
func NewFilteredListViewModel[T HasID](getList func() []T, getFilterFields func(T) []string, shouldRetainSortOrder func() bool) *FilteredListViewModel[T] {
|
||||
filteredList := NewFilteredList(getList, getFilterFields, shouldRetainSortOrder)
|
||||
func NewFilteredListViewModel[T HasID](getList func() []T, getFilterFields func(T) []string) *FilteredListViewModel[T] {
|
||||
filteredList := NewFilteredList(getList, getFilterFields)
|
||||
|
||||
self := &FilteredListViewModel[T]{
|
||||
FilteredList: filteredList,
|
||||
|
|
|
@ -61,10 +61,6 @@ func NewMenuViewModel(c *ContextCommon) *MenuViewModel {
|
|||
self.FilteredListViewModel = NewFilteredListViewModel(
|
||||
func() []*types.MenuItem { return self.menuItems },
|
||||
func(item *types.MenuItem) []string { return item.LabelColumns },
|
||||
// The only menu that the user is likely to filter in is the keybindings
|
||||
// menu; retain the sort order in that one because this allows us to
|
||||
// keep the section headers while filtering:
|
||||
func() bool { return true },
|
||||
)
|
||||
|
||||
return self
|
||||
|
@ -99,6 +95,13 @@ func (self *MenuViewModel) GetDisplayStrings(_ int, _ int) [][]string {
|
|||
}
|
||||
|
||||
func (self *MenuViewModel) GetNonModelItems() []*NonModelItem {
|
||||
// Don't display section headers when we are filtering, and the filter mode
|
||||
// is fuzzy. The reason is that filtering changes the order of the items
|
||||
// (they are sorted by best match), so all the sections would be messed up.
|
||||
if self.FilteredListViewModel.IsFiltering() && self.c.UserConfig.Gui.UseFuzzySearch() {
|
||||
return []*NonModelItem{}
|
||||
}
|
||||
|
||||
result := []*NonModelItem{}
|
||||
menuItems := self.FilteredListViewModel.GetItems()
|
||||
var prevSection *types.MenuSection = nil
|
||||
|
|
|
@ -24,7 +24,6 @@ func NewReflogCommitsContext(c *ContextCommon) *ReflogCommitsContext {
|
|||
func(commit *models.Commit) []string {
|
||||
return []string{commit.ShortSha(), commit.Name}
|
||||
},
|
||||
func() bool { return true },
|
||||
)
|
||||
|
||||
getDisplayStrings := func(_ int, _ int) [][]string {
|
||||
|
|
|
@ -26,7 +26,6 @@ func NewRemoteBranchesContext(
|
|||
func(remoteBranch *models.RemoteBranch) []string {
|
||||
return []string{remoteBranch.Name}
|
||||
},
|
||||
func() bool { return c.AppState.RemoteBranchSortOrder != "alphabetical" },
|
||||
)
|
||||
|
||||
getDisplayStrings := func(_ int, _ int) [][]string {
|
||||
|
|
|
@ -22,7 +22,6 @@ func NewRemotesContext(c *ContextCommon) *RemotesContext {
|
|||
func(remote *models.Remote) []string {
|
||||
return []string{remote.Name}
|
||||
},
|
||||
nil,
|
||||
)
|
||||
|
||||
getDisplayStrings := func(_ int, _ int) [][]string {
|
||||
|
|
|
@ -24,7 +24,6 @@ func NewStashContext(
|
|||
func(stashEntry *models.StashEntry) []string {
|
||||
return []string{stashEntry.Name}
|
||||
},
|
||||
func() bool { return true },
|
||||
)
|
||||
|
||||
getDisplayStrings := func(_ int, _ int) [][]string {
|
||||
|
|
|
@ -19,7 +19,6 @@ func NewSubmodulesContext(c *ContextCommon) *SubmodulesContext {
|
|||
func(submodule *models.SubmoduleConfig) []string {
|
||||
return []string{submodule.FullName()}
|
||||
},
|
||||
nil,
|
||||
)
|
||||
|
||||
getDisplayStrings := func(_ int, _ int) [][]string {
|
||||
|
|
|
@ -24,7 +24,6 @@ func NewTagsContext(
|
|||
func(tag *models.Tag) []string {
|
||||
return []string{tag.Name, tag.Message}
|
||||
},
|
||||
nil,
|
||||
)
|
||||
|
||||
getDisplayStrings := func(_ int, _ int) [][]string {
|
||||
|
|
|
@ -19,7 +19,6 @@ func NewWorktreesContext(c *ContextCommon) *WorktreesContext {
|
|||
func(Worktree *models.Worktree) []string {
|
||||
return []string{Worktree.Name}
|
||||
},
|
||||
nil,
|
||||
)
|
||||
|
||||
getDisplayStrings := func(_ int, _ int) [][]string {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue