diff options
Diffstat (limited to 'pkg/cheatsheet')
-rw-r--r-- | pkg/cheatsheet/generate.go | 31 | ||||
-rw-r--r-- | pkg/cheatsheet/generate_test.go | 31 |
2 files changed, 15 insertions, 47 deletions
diff --git a/pkg/cheatsheet/generate.go b/pkg/cheatsheet/generate.go index 5117e6652..d69a448fb 100644 --- a/pkg/cheatsheet/generate.go +++ b/pkg/cheatsheet/generate.go @@ -21,7 +21,6 @@ import ( "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/i18n" "github.com/jesseduffield/lazygit/pkg/integration" - "github.com/jesseduffield/lazygit/pkg/utils" "github.com/samber/lo" ) @@ -105,10 +104,9 @@ func localisedTitle(tr *i18n.TranslationSet, str string) string { "commits": tr.CommitsTitle, "confirmation": tr.ConfirmationTitle, "information": tr.InformationTitle, - "main": tr.MainTitle, + "main": tr.NormalTitle, "patchBuilding": tr.PatchBuildingTitle, "merging": tr.MergingTitle, - "normal": tr.NormalTitle, "staging": tr.StagingTitle, "menu": tr.MenuTitle, "search": tr.SearchTitle, @@ -127,12 +125,17 @@ func localisedTitle(tr *i18n.TranslationSet, str string) string { } func getBindingSections(bindings []*types.Binding, tr *i18n.TranslationSet) []*bindingSection { + excludedViews := []string{"stagingSecondary", "patchBuildingSecondary"} bindingsToDisplay := slices.Filter(bindings, func(binding *types.Binding) bool { - return binding.Description != "" || binding.Alternative != "" + if lo.Contains(excludedViews, binding.ViewName) { + return false + } + + return (binding.Description != "" || binding.Alternative != "") }) - bindingsByHeader := utils.MuiltiGroupBy(bindingsToDisplay, func(binding *types.Binding) []header { - return getHeaders(binding, tr) + bindingsByHeader := lo.GroupBy(bindingsToDisplay, func(binding *types.Binding) header { + return getHeader(binding, tr) }) bindingGroups := maps.MapToSlice( @@ -164,24 +167,16 @@ func getBindingSections(bindings []*types.Binding, tr *i18n.TranslationSet) []*b }) } -// a binding may belong to multiple headers if it is applicable to multiple contexts, -// for example the copy-to-clipboard binding. -func getHeaders(binding *types.Binding, tr *i18n.TranslationSet) []header { +func getHeader(binding *types.Binding, tr *i18n.TranslationSet) header { if binding.Tag == "navigation" { - return []header{{priority: 2, title: localisedTitle(tr, "navigation")}} + return header{priority: 2, title: localisedTitle(tr, "navigation")} } if binding.ViewName == "" { - return []header{{priority: 3, title: localisedTitle(tr, "global")}} + return header{priority: 3, title: localisedTitle(tr, "global")} } - if len(binding.Contexts) == 0 { - return []header{} - } - - return slices.Map(binding.Contexts, func(context string) header { - return header{priority: 1, title: localisedTitle(tr, context)} - }) + return header{priority: 1, title: localisedTitle(tr, binding.ViewName)} } func formatSections(tr *i18n.TranslationSet, bindingSections []*bindingSection) string { diff --git a/pkg/cheatsheet/generate_test.go b/pkg/cheatsheet/generate_test.go index 149ed28c7..44c49a461 100644 --- a/pkg/cheatsheet/generate_test.go +++ b/pkg/cheatsheet/generate_test.go @@ -26,7 +26,6 @@ func TestGetBindingSections(t *testing.T) { bindings: []*types.Binding{ { ViewName: "files", - Contexts: []string{"files"}, Description: "stage file", }, }, @@ -36,7 +35,6 @@ func TestGetBindingSections(t *testing.T) { bindings: []*types.Binding{ { ViewName: "files", - Contexts: []string{"files"}, Description: "stage file", }, }, @@ -69,17 +67,14 @@ func TestGetBindingSections(t *testing.T) { { ViewName: "files", Description: "stage file", - Contexts: []string{"files"}, }, { ViewName: "files", Description: "unstage file", - Contexts: []string{"files"}, }, { - ViewName: "files", + ViewName: "submodules", Description: "drop submodule", - Contexts: []string{"submodules"}, }, }, expected: []*bindingSection{ @@ -89,12 +84,10 @@ func TestGetBindingSections(t *testing.T) { { ViewName: "files", Description: "stage file", - Contexts: []string{"files"}, }, { ViewName: "files", Description: "unstage file", - Contexts: []string{"files"}, }, }, }, @@ -102,9 +95,8 @@ func TestGetBindingSections(t *testing.T) { title: "Submodules", bindings: []*types.Binding{ { - ViewName: "files", + ViewName: "submodules", Description: "drop submodule", - Contexts: []string{"submodules"}, }, }, }, @@ -115,23 +107,19 @@ func TestGetBindingSections(t *testing.T) { bindings: []*types.Binding{ { ViewName: "files", - Contexts: []string{"files"}, Description: "stage file", }, { ViewName: "files", - Contexts: []string{"files"}, Description: "unstage file", }, { ViewName: "files", - Contexts: []string{"files"}, Description: "scroll", Tag: "navigation", }, { ViewName: "commits", - Contexts: []string{"commits"}, Description: "revert commit", }, }, @@ -141,7 +129,6 @@ func TestGetBindingSections(t *testing.T) { bindings: []*types.Binding{ { ViewName: "files", - Contexts: []string{"files"}, Description: "scroll", Tag: "navigation", }, @@ -152,7 +139,6 @@ func TestGetBindingSections(t *testing.T) { bindings: []*types.Binding{ { ViewName: "commits", - Contexts: []string{"commits"}, Description: "revert commit", }, }, @@ -162,12 +148,10 @@ func TestGetBindingSections(t *testing.T) { bindings: []*types.Binding{ { ViewName: "files", - Contexts: []string{"files"}, Description: "stage file", }, { ViewName: "files", - Contexts: []string{"files"}, Description: "unstage file", }, }, @@ -179,34 +163,28 @@ func TestGetBindingSections(t *testing.T) { bindings: []*types.Binding{ { ViewName: "files", - Contexts: []string{"files"}, Description: "stage file", }, { ViewName: "files", - Contexts: []string{"files"}, Description: "unstage file", }, { ViewName: "files", - Contexts: []string{"files"}, Description: "scroll", Tag: "navigation", }, { ViewName: "commits", - Contexts: []string{"commits"}, Description: "revert commit", }, { ViewName: "commits", - Contexts: []string{"commits"}, Description: "scroll", Tag: "navigation", }, { ViewName: "commits", - Contexts: []string{"commits"}, Description: "page up", Tag: "navigation", }, @@ -217,13 +195,11 @@ func TestGetBindingSections(t *testing.T) { bindings: []*types.Binding{ { ViewName: "files", - Contexts: []string{"files"}, Description: "scroll", Tag: "navigation", }, { ViewName: "commits", - Contexts: []string{"commits"}, Description: "page up", Tag: "navigation", }, @@ -234,7 +210,6 @@ func TestGetBindingSections(t *testing.T) { bindings: []*types.Binding{ { ViewName: "commits", - Contexts: []string{"commits"}, Description: "revert commit", }, }, @@ -244,12 +219,10 @@ func TestGetBindingSections(t *testing.T) { bindings: []*types.Binding{ { ViewName: "files", - Contexts: []string{"files"}, Description: "stage file", }, { ViewName: "files", - Contexts: []string{"files"}, Description: "unstage file", }, }, |