summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-07-20 21:17:14 +1000
committerGitHub <noreply@github.com>2023-07-20 21:17:14 +1000
commit1f920ae6ba781d5862b8bd66084c2a75da3f3076 (patch)
treeea880bf1e8785e4145b8925a8003d3322c21a631
parenta548b289ef8531d12ba74666a8fcf0aa8dde628f (diff)
parent932e01b41ac3203b43ec786b8d9c25334e3e1623 (diff)
Fix crash on empty menu (#2799)
-rw-r--r--pkg/gui/context/menu_context.go4
-rw-r--r--pkg/gui/controllers/helpers/confirmation_helper.go7
-rw-r--r--pkg/gui/controllers/menu_controller.go4
-rw-r--r--pkg/integration/tests/test_list.go1
-rw-r--r--pkg/integration/tests/ui/empty_menu.go31
5 files changed, 45 insertions, 2 deletions
diff --git a/pkg/gui/context/menu_context.go b/pkg/gui/context/menu_context.go
index 088640ea0..a353a4e0d 100644
--- a/pkg/gui/context/menu_context.go
+++ b/pkg/gui/context/menu_context.go
@@ -135,6 +135,10 @@ func (self *MenuContext) OnMenuPress(selectedItem *types.MenuItem) error {
return err
}
+ if selectedItem == nil {
+ return nil
+ }
+
if err := selectedItem.OnPress(); err != nil {
return err
}
diff --git a/pkg/gui/controllers/helpers/confirmation_helper.go b/pkg/gui/controllers/helpers/confirmation_helper.go
index c721310b2..fe18dd638 100644
--- a/pkg/gui/controllers/helpers/confirmation_helper.go
+++ b/pkg/gui/controllers/helpers/confirmation_helper.go
@@ -302,7 +302,12 @@ func (self *ConfirmationHelper) resizeMenu() {
_, _ = self.c.GocuiGui().SetView(self.c.Views().Menu.Name(), x0, y0, x1, menuBottom, 0)
tooltipTop := menuBottom + 1
- tooltipHeight := getMessageHeight(true, self.c.Contexts().Menu.GetSelected().Tooltip, panelWidth) + 2 // plus 2 for the frame
+ tooltip := ""
+ selectedItem := self.c.Contexts().Menu.GetSelected()
+ if selectedItem != nil {
+ tooltip = selectedItem.Tooltip
+ }
+ tooltipHeight := getMessageHeight(true, tooltip, panelWidth) + 2 // plus 2 for the frame
_, _ = self.c.GocuiGui().SetView(self.c.Views().Tooltip.Name(), x0, tooltipTop, x1, tooltipTop+tooltipHeight-1, 0)
}
diff --git a/pkg/gui/controllers/menu_controller.go b/pkg/gui/controllers/menu_controller.go
index 3b04f01f2..c9ba2c701 100644
--- a/pkg/gui/controllers/menu_controller.go
+++ b/pkg/gui/controllers/menu_controller.go
@@ -53,7 +53,9 @@ func (self *MenuController) GetOnClick() func() error {
func (self *MenuController) GetOnFocus() func(types.OnFocusOpts) error {
return func(types.OnFocusOpts) error {
selectedMenuItem := self.context().GetSelected()
- self.c.Views().Tooltip.SetContent(selectedMenuItem.Tooltip)
+ if selectedMenuItem != nil {
+ self.c.Views().Tooltip.SetContent(selectedMenuItem.Tooltip)
+ }
return nil
}
}
diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go
index caaf2039e..5eab827b7 100644
--- a/pkg/integration/tests/test_list.go
+++ b/pkg/integration/tests/test_list.go
@@ -211,6 +211,7 @@ var tests = []*components.IntegrationTest{
tag.Reset,
ui.Accordion,
ui.DoublePopup,
+ ui.EmptyMenu,
ui.SwitchTabFromMenu,
undo.UndoCheckoutAndDrop,
undo.UndoDrop,
diff --git a/pkg/integration/tests/ui/empty_menu.go b/pkg/integration/tests/ui/empty_menu.go
new file mode 100644
index 000000000..d6b3b42f0
--- /dev/null
+++ b/pkg/integration/tests/ui/empty_menu.go
@@ -0,0 +1,31 @@
+package ui
+
+import (
+ "github.com/jesseduffield/lazygit/pkg/config"
+ . "github.com/jesseduffield/lazygit/pkg/integration/components"
+)
+
+var EmptyMenu = NewIntegrationTest(NewIntegrationTestArgs{
+ Description: "Verify that we don't crash on an empty menu",
+ ExtraCmdArgs: []string{},
+ Skip: false,
+ SetupConfig: func(config *config.AppConfig) {},
+ SetupRepo: func(shell *Shell) {
+ },
+ Run: func(t *TestDriver, keys config.KeybindingConfig) {
+ t.Views().Files().
+ IsFocused().
+ Press(keys.Universal.OptionMenu)
+
+ t.Views().Menu().
+ IsFocused().
+ // a string that filters everything out
+ FilterOrSearch("ljasldkjaslkdjalskdjalsdjaslkd").
+ IsEmpty().
+ Press(keys.Universal.Select)
+
+ // back in the files view, selecting the non-existing menu item was a no-op
+ t.Views().Files().
+ IsFocused()
+ },
+})