mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-06-11 22:30:56 +02:00
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:
@@ -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 {
|
||||
|
||||
@@ -466,6 +466,7 @@ var tests = []*components.IntegrationTest{
|
||||
ui.Accordion,
|
||||
ui.DisableSwitchTabWithPanelJumpKeys,
|
||||
ui.EmptyMenu,
|
||||
ui.KeybindingSuggestionsDontCrashOnDisabledBindings,
|
||||
ui.KeybindingSuggestionsWhenSwitchingRepos,
|
||||
ui.ModeSpecificKeybindingSuggestions,
|
||||
ui.OpenLinkFailure,
|
||||
|
||||
@@ -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: ?"))
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user