diff options
author | Stefan Haller <stefan@haller-berlin.de> | 2024-03-17 12:11:24 +0100 |
---|---|---|
committer | Stefan Haller <stefan@haller-berlin.de> | 2024-03-17 12:23:07 +0100 |
commit | 4f2bebe453c42ac9fd9896eb32cf044eb3af1697 (patch) | |
tree | 7c46788062778830daf82c9d713c7b7bdffff876 | |
parent | 7d2163d63297063364a18a4d62077badc1c1f47e (diff) |
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.
-rw-r--r-- | pkg/gui/context/branches_context.go | 1 | ||||
-rw-r--r-- | pkg/gui/context/filtered_list.go | 19 | ||||
-rw-r--r-- | pkg/gui/context/filtered_list_view_model.go | 4 | ||||
-rw-r--r-- | pkg/gui/context/menu_context.go | 11 | ||||
-rw-r--r-- | pkg/gui/context/reflog_commits_context.go | 1 | ||||
-rw-r--r-- | pkg/gui/context/remote_branches_context.go | 1 | ||||
-rw-r--r-- | pkg/gui/context/remotes_context.go | 1 | ||||
-rw-r--r-- | pkg/gui/context/stash_context.go | 1 | ||||
-rw-r--r-- | pkg/gui/context/submodules_context.go | 1 | ||||
-rw-r--r-- | pkg/gui/context/tags_context.go | 1 | ||||
-rw-r--r-- | pkg/gui/context/worktrees_context.go | 1 |
11 files changed, 13 insertions, 29 deletions
diff --git a/pkg/gui/context/branches_context.go b/pkg/gui/context/branches_context.go index 6317a60b2..d2647ef84 100644 --- a/pkg/gui/context/branches_context.go +++ b/pkg/gui/context/branches_context.go @@ -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 { diff --git a/pkg/gui/context/filtered_list.go b/pkg/gui/context/filtered_list.go index 8ac912cd0..0724ecb3b 100644 --- a/pkg/gui/context/filtered_list.go +++ b/pkg/gui/context/filtered_list.go @@ -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) - } } } diff --git a/pkg/gui/context/filtered_list_view_model.go b/pkg/gui/context/filtered_list_view_model.go index b52fcbc0a..2c2841964 100644 --- a/pkg/gui/context/filtered_list_view_model.go +++ b/pkg/gui/context/filtered_list_view_model.go @@ -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, diff --git a/pkg/gui/context/menu_context.go b/pkg/gui/context/menu_context.go index 2158d5c7a..9db09b74f 100644 --- a/pkg/gui/context/menu_context.go +++ b/pkg/gui/context/menu_context.go @@ -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 diff --git a/pkg/gui/context/reflog_commits_context.go b/pkg/gui/context/reflog_commits_context.go index 6791932ba..65137d633 100644 --- a/pkg/gui/context/reflog_commits_context.go +++ b/pkg/gui/context/reflog_commits_context.go @@ -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 { diff --git a/pkg/gui/context/remote_branches_context.go b/pkg/gui/context/remote_branches_context.go index 9de792f27..884d3debb 100644 --- a/pkg/gui/context/remote_branches_context.go +++ b/pkg/gui/context/remote_branches_context.go @@ -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 { diff --git a/pkg/gui/context/remotes_context.go b/pkg/gui/context/remotes_context.go index 51fc1c036..73ea428aa 100644 --- a/pkg/gui/context/remotes_context.go +++ b/pkg/gui/context/remotes_context.go @@ -22,7 +22,6 @@ func NewRemotesContext(c *ContextCommon) *RemotesContext { func(remote *models.Remote) []string { return []string{remote.Name} }, - nil, ) getDisplayStrings := func(_ int, _ int) [][]string { diff --git a/pkg/gui/context/stash_context.go b/pkg/gui/context/stash_context.go index c832f85ff..c8d487688 100644 --- a/pkg/gui/context/stash_context.go +++ b/pkg/gui/context/stash_context.go @@ -24,7 +24,6 @@ func NewStashContext( func(stashEntry *models.StashEntry) []string { return []string{stashEntry.Name} }, - func() bool { return true }, ) getDisplayStrings := func(_ int, _ int) [][]string { diff --git a/pkg/gui/context/submodules_context.go b/pkg/gui/context/submodules_context.go index dbd12077a..5428da044 100644 --- a/pkg/gui/context/submodules_context.go +++ b/pkg/gui/context/submodules_context.go @@ -19,7 +19,6 @@ func NewSubmodulesContext(c *ContextCommon) *SubmodulesContext { func(submodule *models.SubmoduleConfig) []string { return []string{submodule.FullName()} }, - nil, ) getDisplayStrings := func(_ int, _ int) [][]string { diff --git a/pkg/gui/context/tags_context.go b/pkg/gui/context/tags_context.go index c5ae2ccd5..d827564dd 100644 --- a/pkg/gui/context/tags_context.go +++ b/pkg/gui/context/tags_context.go @@ -24,7 +24,6 @@ func NewTagsContext( func(tag *models.Tag) []string { return []string{tag.Name, tag.Message} }, - nil, ) getDisplayStrings := func(_ int, _ int) [][]string { diff --git a/pkg/gui/context/worktrees_context.go b/pkg/gui/context/worktrees_context.go index 55618de85..3e45f2d45 100644 --- a/pkg/gui/context/worktrees_context.go +++ b/pkg/gui/context/worktrees_context.go @@ -19,7 +19,6 @@ func NewWorktreesContext(c *ContextCommon) *WorktreesContext { func(Worktree *models.Worktree) []string { return []string{Worktree.Name} }, - nil, ) getDisplayStrings := func(_ int, _ int) [][]string { |