1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-30 03:23:08 +03:00

Add a prompt for the sort order menus for branches

This commit is contained in:
Stefan Haller
2025-07-08 17:32:51 +02:00
parent 6bfcb3d6f0
commit df48667253
7 changed files with 40 additions and 22 deletions

View File

@ -673,7 +673,10 @@ func (self *BranchesController) createTag(branch *models.Branch) error {
} }
func (self *BranchesController) createSortMenu() error { func (self *BranchesController) createSortMenu() error {
return self.c.Helpers().Refs.CreateSortOrderMenu([]string{"recency", "alphabetical", "date"}, func(sortOrder string) error { return self.c.Helpers().Refs.CreateSortOrderMenu(
[]string{"recency", "alphabetical", "date"},
self.c.Tr.SortOrderPromptLocalBranches,
func(sortOrder string) error {
if self.c.UserConfig().Git.LocalBranchSortOrder != sortOrder { if self.c.UserConfig().Git.LocalBranchSortOrder != sortOrder {
self.c.UserConfig().Git.LocalBranchSortOrder = sortOrder self.c.UserConfig().Git.LocalBranchSortOrder = sortOrder
self.c.Contexts().Branches.SetSelection(0) self.c.Contexts().Branches.SetSelection(0)

View File

@ -186,7 +186,7 @@ func (self *RefsHelper) ResetToRef(ref string, strength string, envVars []string
return nil return nil
} }
func (self *RefsHelper) CreateSortOrderMenu(sortOptionsOrder []string, onSelected func(sortOrder string) error, currentValue string) error { func (self *RefsHelper) CreateSortOrderMenu(sortOptionsOrder []string, menuPrompt string, onSelected func(sortOrder string) error, currentValue string) error {
type sortMenuOption struct { type sortMenuOption struct {
key types.Key key types.Key
label string label string
@ -224,6 +224,7 @@ func (self *RefsHelper) CreateSortOrderMenu(sortOptionsOrder []string, onSelecte
return self.c.Menu(types.CreateMenuOptions{ return self.c.Menu(types.CreateMenuOptions{
Title: self.c.Tr.SortOrder, Title: self.c.Tr.SortOrder,
Items: menuItems, Items: menuItems,
Prompt: menuPrompt,
}) })
} }

View File

@ -145,7 +145,10 @@ func (self *RemoteBranchesController) rebase(selectedBranch *models.RemoteBranch
} }
func (self *RemoteBranchesController) createSortMenu() error { func (self *RemoteBranchesController) createSortMenu() error {
return self.c.Helpers().Refs.CreateSortOrderMenu([]string{"alphabetical", "date"}, func(sortOrder string) error { return self.c.Helpers().Refs.CreateSortOrderMenu(
[]string{"alphabetical", "date"},
self.c.Tr.SortOrderPromptRemoteBranches,
func(sortOrder string) error {
if self.c.UserConfig().Git.RemoteBranchSortOrder != sortOrder { if self.c.UserConfig().Git.RemoteBranchSortOrder != sortOrder {
self.c.UserConfig().Git.RemoteBranchSortOrder = sortOrder self.c.UserConfig().Git.RemoteBranchSortOrder = sortOrder
self.c.Contexts().RemoteBranches.SetSelection(0) self.c.Contexts().RemoteBranches.SetSelection(0)

View File

@ -760,10 +760,13 @@ type TranslationSet struct {
ShowGitGraph string ShowGitGraph string
ShowGitGraphTooltip string ShowGitGraphTooltip string
SortOrder string SortOrder string
SortOrderPromptLocalBranches string
SortOrderPromptRemoteBranches string
SortAlphabetical string SortAlphabetical string
SortByDate string SortByDate string
SortByRecency string SortByRecency string
SortBasedOnReflog string SortBasedOnReflog string
SortOrderPrompt string
SortCommits string SortCommits string
SortCommitsTooltip string SortCommitsTooltip string
CantChangeContextSizeError string CantChangeContextSizeError string
@ -1807,6 +1810,8 @@ func EnglishTranslationSet() *TranslationSet {
ShowGitGraph: "Show git graph", ShowGitGraph: "Show git graph",
ShowGitGraphTooltip: "Show or hide the git graph in the commit log.\n\nThe default can be changed in the config file with the key 'git.log.showGraph'.", ShowGitGraphTooltip: "Show or hide the git graph in the commit log.\n\nThe default can be changed in the config file with the key 'git.log.showGraph'.",
SortOrder: "Sort order", SortOrder: "Sort order",
SortOrderPromptLocalBranches: "The default sort order for local branches can be set in the config file with the key 'git.localBranchSortOrder'.",
SortOrderPromptRemoteBranches: "The default sort order for remote branches can be set in the config file with the key 'git.remoteBranchSortOrder'.",
SortAlphabetical: "Alphabetical", SortAlphabetical: "Alphabetical",
SortByDate: "Date", SortByDate: "Date",
SortByRecency: "Recency", SortByRecency: "Recency",

View File

@ -50,6 +50,12 @@ func (self *MenuDriver) TopLines(matchers ...*TextMatcher) *MenuDriver {
return self return self
} }
func (self *MenuDriver) ContainsLines(matchers ...*TextMatcher) *MenuDriver {
self.getViewDriver().ContainsLines(matchers...)
return self
}
func (self *MenuDriver) Filter(text string) *MenuDriver { func (self *MenuDriver) Filter(text string) *MenuDriver {
self.getViewDriver().FilterOrSearch(text) self.getViewDriver().FilterOrSearch(text)

View File

@ -37,7 +37,7 @@ var SortLocalBranches = NewIntegrationTest(NewIntegrationTestArgs{
Press(keys.Branches.SortOrder) Press(keys.Branches.SortOrder)
t.ExpectPopup().Menu().Title(Equals("Sort order")). t.ExpectPopup().Menu().Title(Equals("Sort order")).
Lines( ContainsLines(
Contains("r ( ) Recency").IsSelected(), Contains("r ( ) Recency").IsSelected(),
Contains("a ( ) Alphabetical"), Contains("a ( ) Alphabetical"),
Contains("d (•) Date"), Contains("d (•) Date"),
@ -59,7 +59,7 @@ var SortLocalBranches = NewIntegrationTest(NewIntegrationTestArgs{
Press(keys.Branches.SortOrder) Press(keys.Branches.SortOrder)
t.ExpectPopup().Menu().Title(Equals("Sort order")). t.ExpectPopup().Menu().Title(Equals("Sort order")).
Lines( ContainsLines(
Contains("r (•) Recency").IsSelected(), Contains("r (•) Recency").IsSelected(),
Contains("a ( ) Alphabetical"), Contains("a ( ) Alphabetical"),
Contains("d ( ) Date"), Contains("d ( ) Date"),

View File

@ -41,7 +41,7 @@ var SortRemoteBranches = NewIntegrationTest(NewIntegrationTestArgs{
Press(keys.Branches.SortOrder) Press(keys.Branches.SortOrder)
t.ExpectPopup().Menu().Title(Equals("Sort order")). t.ExpectPopup().Menu().Title(Equals("Sort order")).
Lines( ContainsLines(
Contains("a ( ) Alphabetical").IsSelected(), Contains("a ( ) Alphabetical").IsSelected(),
Contains("d (•) Date"), Contains("d (•) Date"),
Contains(" Cancel"), Contains(" Cancel"),