diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-10-02 07:32:48 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-10-02 08:09:42 +1000 |
commit | 7be474bd83a0fc01e67e1cfd92f1ed9e098b3bee (patch) | |
tree | 36b01e7b6531ef98f9f507f1ecc610070ebf52db /scripts | |
parent | 30b347861101a4a3f38a009ed8ef8b50860472ae (diff) |
update keybindings
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/generate_cheatsheet.go | 46 |
1 files changed, 35 insertions, 11 deletions
diff --git a/scripts/generate_cheatsheet.go b/scripts/generate_cheatsheet.go index 0b468f2d0..53a816ff5 100644 --- a/scripts/generate_cheatsheet.go +++ b/scripts/generate_cheatsheet.go @@ -72,13 +72,31 @@ func getBindingSections(mApp *app.App) []*bindingSection { bindings := mApp.Gui.GetInitialKeybindings() type contextAndViewType struct { - context string - viewName string + subtitle string + title string } contextAndViewBindingMap := map[contextAndViewType][]*gui.Binding{} +outer: for _, binding := range bindings { + if binding.Tag == "navigation" { + key := contextAndViewType{subtitle: "", title: "navigation"} + existing := contextAndViewBindingMap[key] + if existing == nil { + contextAndViewBindingMap[key] = []*gui.Binding{binding} + } else { + for _, navBinding := range contextAndViewBindingMap[key] { + if navBinding.Description == binding.Description { + continue outer + } + } + contextAndViewBindingMap[key] = append(contextAndViewBindingMap[key], binding) + } + + continue outer + } + contexts := []string{} if len(binding.Contexts) == 0 { contexts = append(contexts, "") @@ -87,7 +105,7 @@ func getBindingSections(mApp *app.App) []*bindingSection { } for _, context := range contexts { - key := contextAndViewType{context: context, viewName: binding.ViewName} + key := contextAndViewType{subtitle: context, title: binding.ViewName} existing := contextAndViewBindingMap[key] if existing == nil { contextAndViewBindingMap[key] = []*gui.Binding{binding} @@ -111,33 +129,39 @@ func getBindingSections(mApp *app.App) []*bindingSection { sort.Slice(groupedBindings, func(i, j int) bool { first := groupedBindings[i].contextAndView second := groupedBindings[j].contextAndView - if first.viewName == "" { + if first.title == "" { + return true + } + if second.title == "" { + return false + } + if first.title == "navigation" { return true } - if second.viewName == "" { + if second.title == "navigation" { return false } - return first.viewName < second.viewName || (first.viewName == second.viewName && first.context < second.context) + return first.title < second.title || (first.title == second.title && first.subtitle < second.subtitle) }) for _, group := range groupedBindings { contextAndView := group.contextAndView contextBindings := group.bindings - mApp.Log.Info("viewname: " + contextAndView.viewName + ", context: " + contextAndView.context) - viewName := contextAndView.viewName + mApp.Log.Info("viewname: " + contextAndView.title + ", context: " + contextAndView.subtitle) + viewName := contextAndView.title if viewName == "" { viewName = "global" } translatedView := localisedTitle(mApp, viewName) var title string - if contextAndView.context == "" { + if contextAndView.subtitle == "" { addendum := " " + mApp.Tr.SLocalize("Panel") - if viewName == "global" { + if viewName == "global" || viewName == "navigation" { addendum = "" } title = fmt.Sprintf("%s%s", translatedView, addendum) } else { - translatedContextName := localisedTitle(mApp, contextAndView.context) + translatedContextName := localisedTitle(mApp, contextAndView.subtitle) title = fmt.Sprintf("%s %s (%s)", translatedView, mApp.Tr.SLocalize("Panel"), translatedContextName) } |