Fix crash when keybindings are disabled that normally show in the status bar (#5655)

If a keybinding that we want to display in the options bar was set to
`<disabled>` 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
3d18ee8f91). Fix the crash by not showing those commands at all.
This commit is contained in:
Stefan Haller 2026-05-28 19:31:42 +02:00 committed by GitHub
commit ff8f3d790e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 24 additions and 2 deletions

View file

@ -46,11 +46,11 @@ 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 {
return binding.DisplayOnScreen && !binding.IsDisabled()
return len(binding.Keys) > 0 && binding.DisplayOnScreen && !binding.IsDisabled()
})
optionsMap := lo.Map(bindingsToDisplay, func(binding *types.Binding, _ int) bindingInfo {

View file

@ -466,6 +466,7 @@ var tests = []*components.IntegrationTest{
ui.Accordion,
ui.DisableSwitchTabWithPanelJumpKeys,
ui.EmptyMenu,
ui.KeybindingSuggestionsDontCrashOnDisabledBindings,
ui.KeybindingSuggestionsWhenSwitchingRepos,
ui.ModeSpecificKeybindingSuggestions,
ui.OpenLinkFailure,

View file

@ -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: ?"))
},
})