From 4961c4b678f82d5a8e2509aaabd9a3b43db00b24 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Tue, 12 Aug 2025 14:11:43 +0200 Subject: [PATCH] Avoid duplicate key bindings in options map Sometimes there is a local and a global keybinding for the same key; if both are configured to be shown in the options map, we should only show the local one because it takes precedence. This happens for example for in a popup, or for in the focused main view. Note that this is also a problem in the keybindings menu, and we don't solve that here. --- pkg/gui/options_map.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/gui/options_map.go b/pkg/gui/options_map.go index bacc3b106..455215468 100644 --- a/pkg/gui/options_map.go +++ b/pkg/gui/options_map.go @@ -4,6 +4,7 @@ import ( "fmt" "strings" + "github.com/jesseduffield/generics/set" "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers" "github.com/jesseduffield/lazygit/pkg/gui/keybindings" @@ -38,7 +39,14 @@ func (self *OptionsMapMgr) renderContextOptionsMap() { currentContextBindings := currentContext.GetKeybindings(self.c.KeybindingsOpts()) globalBindings := self.c.Contexts().Global.GetKeybindings(self.c.KeybindingsOpts()) - allBindings := append(currentContextBindings, globalBindings...) + currentContextKeys := set.NewFromSlice( + lo.Map(currentContextBindings, func(binding *types.Binding, _ int) types.Key { + return binding.Key + })) + + allBindings := append(currentContextBindings, lo.Filter(globalBindings, func(b *types.Binding, _ int) bool { + return !currentContextKeys.Includes(b.Key) + })...) bindingsToDisplay := lo.Filter(allBindings, func(binding *types.Binding, _ int) bool { return binding.DisplayOnScreen && !binding.IsDisabled()