Skip to content

Commit 1fdaf80

Browse files
committed
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 <esc> in a popup, or for <esc> in the focused main view. Note that this is also a problem in the keybindings menu, and we don't solve that here.
1 parent de5a7ee commit 1fdaf80

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

pkg/gui/options_map.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"strings"
66

7+
"github.com/jesseduffield/generics/set"
78
"github.com/jesseduffield/lazygit/pkg/gui/context"
89
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
910
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
@@ -38,7 +39,14 @@ func (self *OptionsMapMgr) renderContextOptionsMap() {
3839
currentContextBindings := currentContext.GetKeybindings(self.c.KeybindingsOpts())
3940
globalBindings := self.c.Contexts().Global.GetKeybindings(self.c.KeybindingsOpts())
4041

41-
allBindings := append(currentContextBindings, globalBindings...)
42+
currentContextKeys := set.NewFromSlice(
43+
lo.Map(currentContextBindings, func(binding *types.Binding, _ int) types.Key {
44+
return binding.Key
45+
}))
46+
47+
allBindings := append(currentContextBindings, lo.Filter(globalBindings, func(b *types.Binding, _ int) bool {
48+
return !currentContextKeys.Includes(b.Key)
49+
})...)
4250

4351
bindingsToDisplay := lo.Filter(allBindings, func(binding *types.Binding, _ int) bool {
4452
return binding.DisplayOnScreen && !binding.IsDisabled()

0 commit comments

Comments
 (0)