Skip to content

Commit ebfc7ff

Browse files
authored
Don't show keybindings option in bottom line when panel is open (#4143)
- **PR Description** Hide the `Keybindings: ?` option from the bottom line if a panel is open. - **Please check if the PR fulfills these requirements** * [x] Cheatsheets are up-to-date (run `go generate ./...`) * [x] Code has been formatted (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting)) * [ ] Tests have been added/updated (see [here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md) for the integration test guide) * [ ] Text is internationalised (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation)) * [ ] If a new UserConfig entry was added, make sure it can be hot-reloaded (see [here](https://github.com/jesseduffield/lazygit/blob/master/docs/dev/Codebase_Guide.md#using-userconfig)) * [ ] Docs have been updated if necessary * [x] You've read through your own file changes for silly mistakes etc
2 parents 9776be3 + 928e76a commit ebfc7ff

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

pkg/gui/controllers/global_controller.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,11 @@ func (self *GlobalController) GetKeybindings(opts types.KeybindingsOpts) []*type
6969
Modifier: gocui.ModNone,
7070
// we have the description on the alt key and not the main key for legacy reasons
7171
// (the original main key was 'x' but we've reassigned that to other purposes)
72-
Description: self.c.Tr.OpenKeybindingsMenu,
73-
Handler: self.createOptionsMenu,
74-
ShortDescription: self.c.Tr.Keybindings,
75-
DisplayOnScreen: true,
72+
Description: self.c.Tr.OpenKeybindingsMenu,
73+
Handler: self.createOptionsMenu,
74+
ShortDescription: self.c.Tr.Keybindings,
75+
DisplayOnScreen: true,
76+
GetDisabledReason: self.optionsMenuDisabledReason,
7677
},
7778
{
7879
ViewName: "",
@@ -156,6 +157,17 @@ func (self *GlobalController) createOptionsMenu() error {
156157
return (&OptionsMenuAction{c: self.c}).Call()
157158
}
158159

160+
func (self *GlobalController) optionsMenuDisabledReason() *types.DisabledReason {
161+
ctx := self.c.Context().Current()
162+
// Don't show options menu while displaying popup.
163+
if ctx.GetKind() == types.PERSISTENT_POPUP || ctx.GetKind() == types.TEMPORARY_POPUP {
164+
// The empty error text is intentional. We don't want to show an error
165+
// toast for this, but only hide it from the options map.
166+
return &types.DisabledReason{Text: ""}
167+
}
168+
return nil
169+
}
170+
159171
func (self *GlobalController) createFilteringMenu() error {
160172
return (&FilteringMenuAction{c: self.c}).Call()
161173
}

pkg/gui/controllers/options_menu_action.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ type OptionsMenuAction struct {
1313

1414
func (self *OptionsMenuAction) Call() error {
1515
ctx := self.c.Context().Current()
16-
// Don't show menu while displaying popup.
17-
if ctx.GetKind() == types.PERSISTENT_POPUP || ctx.GetKind() == types.TEMPORARY_POPUP {
18-
return nil
19-
}
20-
2116
local, global, navigation := self.getBindings(ctx)
2217

2318
menuItems := []*types.MenuItem{}

pkg/gui/keybindings.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,9 @@ func (gui *Gui) callKeybindingHandler(binding *types.Binding) error {
453453
return errors.New(disabledReason.Text)
454454
}
455455

456-
gui.c.ErrorToast(gui.Tr.DisabledMenuItemPrefix + disabledReason.Text)
456+
if len(disabledReason.Text) > 0 {
457+
gui.c.ErrorToast(gui.Tr.DisabledMenuItemPrefix + disabledReason.Text)
458+
}
457459
return nil
458460
}
459461
return binding.Handler()

0 commit comments

Comments
 (0)