From 76d0dc15ca6114e1d937d95d81d7a9b9f8f4d176 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 28 May 2026 19:19:05 +0200 Subject: [PATCH 1/2] Fix crash when keybindings are disabled that we want to show in the status bar If a keybinding that we want to display in the options bar was set to by the user, in pre-0.62 versions we would still display the command, but with no keybinding. This was arguably not very useful before, but now it actually crashes because we would now try to display the first key of the slice of configured keys (crash introduced in 3d18ee8f91c7). Fix the crash by not showing those commands at all. --- pkg/gui/options_map.go | 2 +- pkg/integration/tests/test_list.go | 1 + ...estions_dont_crash_on_disabled_bindings.go | 21 +++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 pkg/integration/tests/ui/keybinding_suggestions_dont_crash_on_disabled_bindings.go diff --git a/pkg/gui/options_map.go b/pkg/gui/options_map.go index 890d2f2de1e..b4094acee20 100644 --- a/pkg/gui/options_map.go +++ b/pkg/gui/options_map.go @@ -50,7 +50,7 @@ func (self *OptionsMapMgr) renderContextOptionsMap() { })...) bindingsToDisplay := lo.Filter(allBindings, func(binding *types.Binding, _ int) bool { - return binding.DisplayOnScreen && !binding.IsDisabled() + return len(binding.Keys) > 0 && binding.DisplayOnScreen && !binding.IsDisabled() }) optionsMap := lo.Map(bindingsToDisplay, func(binding *types.Binding, _ int) bindingInfo { diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index aea37515b6d..2bf2837cdf1 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -466,6 +466,7 @@ var tests = []*components.IntegrationTest{ ui.Accordion, ui.DisableSwitchTabWithPanelJumpKeys, ui.EmptyMenu, + ui.KeybindingSuggestionsDontCrashOnDisabledBindings, ui.KeybindingSuggestionsWhenSwitchingRepos, ui.ModeSpecificKeybindingSuggestions, ui.OpenLinkFailure, diff --git a/pkg/integration/tests/ui/keybinding_suggestions_dont_crash_on_disabled_bindings.go b/pkg/integration/tests/ui/keybinding_suggestions_dont_crash_on_disabled_bindings.go new file mode 100644 index 00000000000..1db31595f1e --- /dev/null +++ b/pkg/integration/tests/ui/keybinding_suggestions_dont_crash_on_disabled_bindings.go @@ -0,0 +1,21 @@ +package ui + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var KeybindingSuggestionsDontCrashOnDisabledBindings = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Filter out keybinding suggestions whose bindings are disabled", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) { + config.GetUserConfig().Keybinding.Files.StashAllChanges = []string{} + }, + SetupRepo: func(shell *Shell) {}, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Files().Focus() + t.Views().Options().Content( + Equals("Commit: c | Reset: D | Keybindings: ?")) + }, +}) From b3491f4e37d330b2d3f51b2b430f84d8c1133702 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 28 May 2026 19:20:17 +0200 Subject: [PATCH 2/2] Cleanup: filter out empty keybindings earlier This doesn't make a difference for the behavior, it just looks strange to include the empty bindings first and then filter them out in the next statement. --- pkg/gui/options_map.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/gui/options_map.go b/pkg/gui/options_map.go index b4094acee20..962187bfff8 100644 --- a/pkg/gui/options_map.go +++ b/pkg/gui/options_map.go @@ -46,7 +46,7 @@ func (self *OptionsMapMgr) renderContextOptionsMap() { })) allBindings := append(currentContextBindings, lo.Filter(globalBindings, func(b *types.Binding, _ int) bool { - return len(b.Keys) == 0 || !currentContextKeys.Includes(b.Keys[0]) + return len(b.Keys) > 0 && !currentContextKeys.Includes(b.Keys[0]) })...) bindingsToDisplay := lo.Filter(allBindings, func(binding *types.Binding, _ int) bool {