mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-25 12:24:47 +02:00
Fix crash when filtering the keybindings menu (#3450)
- **PR Description** It would crash when some keybindings are set to null, and the filter string is such that only those keybindings remain visible. Fixes #3449.
This commit is contained in:
commit
f93cb54b5d
@ -74,9 +74,6 @@ func (self *MenuViewModel) SetMenuItems(items []*types.MenuItem, columnAlignment
|
|||||||
// TODO: move into presentation package
|
// TODO: move into presentation package
|
||||||
func (self *MenuViewModel) GetDisplayStrings(_ int, _ int) [][]string {
|
func (self *MenuViewModel) GetDisplayStrings(_ int, _ int) [][]string {
|
||||||
menuItems := self.FilteredListViewModel.GetItems()
|
menuItems := self.FilteredListViewModel.GetItems()
|
||||||
showKeys := lo.SomeBy(menuItems, func(item *types.MenuItem) bool {
|
|
||||||
return item.Key != nil
|
|
||||||
})
|
|
||||||
|
|
||||||
return lo.Map(menuItems, func(item *types.MenuItem, _ int) []string {
|
return lo.Map(menuItems, func(item *types.MenuItem, _ int) []string {
|
||||||
displayStrings := item.LabelColumns
|
displayStrings := item.LabelColumns
|
||||||
@ -84,12 +81,12 @@ func (self *MenuViewModel) GetDisplayStrings(_ int, _ int) [][]string {
|
|||||||
displayStrings[0] = style.FgDefault.SetStrikethrough().Sprint(displayStrings[0])
|
displayStrings[0] = style.FgDefault.SetStrikethrough().Sprint(displayStrings[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
if !showKeys {
|
keyLabel := ""
|
||||||
return displayStrings
|
if item.Key != nil {
|
||||||
|
keyLabel = style.FgCyan.Sprint(keybindings.LabelFromKey(item.Key))
|
||||||
}
|
}
|
||||||
|
|
||||||
keyLabel := keybindings.LabelFromKey(item.Key)
|
displayStrings = utils.Prepend(displayStrings, keyLabel)
|
||||||
displayStrings = utils.Prepend(displayStrings, style.FgCyan.Sprint(keyLabel))
|
|
||||||
return displayStrings
|
return displayStrings
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
package filter_and_search
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
|
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
||||||
|
)
|
||||||
|
|
||||||
|
var FilterMenuWithNoKeybindings = NewIntegrationTest(NewIntegrationTestArgs{
|
||||||
|
Description: "Filtering the keybindings menu so that only entries without keybinding are left",
|
||||||
|
ExtraCmdArgs: []string{},
|
||||||
|
Skip: false,
|
||||||
|
SetupConfig: func(config *config.AppConfig) {
|
||||||
|
config.UserConfig.Keybinding.Universal.ToggleWhitespaceInDiffView = "<disabled>"
|
||||||
|
},
|
||||||
|
SetupRepo: func(shell *Shell) {
|
||||||
|
},
|
||||||
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
|
t.Views().Files().
|
||||||
|
IsFocused().
|
||||||
|
Press(keys.Universal.OptionMenu)
|
||||||
|
|
||||||
|
t.ExpectPopup().Menu().
|
||||||
|
Title(Equals("Keybindings")).
|
||||||
|
Filter("whitespace").
|
||||||
|
Lines(
|
||||||
|
// menu has filtered down to the one item that matches the
|
||||||
|
// filter, and it doesn't have a keybinding
|
||||||
|
Equals("--- Global ---"),
|
||||||
|
Equals("Toggle whitespace").IsSelected(),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
})
|
@ -146,6 +146,7 @@ var tests = []*components.IntegrationTest{
|
|||||||
filter_and_search.FilterFuzzy,
|
filter_and_search.FilterFuzzy,
|
||||||
filter_and_search.FilterMenu,
|
filter_and_search.FilterMenu,
|
||||||
filter_and_search.FilterMenuCancelFilterWithEscape,
|
filter_and_search.FilterMenuCancelFilterWithEscape,
|
||||||
|
filter_and_search.FilterMenuWithNoKeybindings,
|
||||||
filter_and_search.FilterRemoteBranches,
|
filter_and_search.FilterRemoteBranches,
|
||||||
filter_and_search.FilterRemotes,
|
filter_and_search.FilterRemotes,
|
||||||
filter_and_search.FilterSearchHistory,
|
filter_and_search.FilterSearchHistory,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user