diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2023-03-21 20:57:52 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2023-04-30 13:19:53 +1000 |
commit | 509e3efa70512ed34b90177eb17d6481664bb958 (patch) | |
tree | 663333126d6764706462271712583e4c8e93d786 /pkg/gui/keybindings.go | |
parent | 8edad826caf2fa48bfad33f9f8c4f3ba49a052da (diff) |
lots more refactoring
Diffstat (limited to 'pkg/gui/keybindings.go')
-rw-r--r-- | pkg/gui/keybindings.go | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 64ca5a190..55dcaa715 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -11,7 +11,17 @@ import ( func (gui *Gui) noPopupPanel(f func() error) func() error { return func() error { - if gui.popupPanelFocused() { + if gui.helpers.Confirmation.IsPopupPanelFocused() { + return nil + } + + return f() + } +} + +func (gui *Gui) outsideFilterMode(f func() error) func() error { + return func() error { + if !gui.validateNotInFilterMode() { return nil } @@ -34,8 +44,7 @@ func (self *Gui) GetCheatsheetKeybindings() []*types.Binding { return bindings } -// renaming receiver to 'self' to aid refactoring. Will probably end up moving all Gui handlers to this pattern eventually. -func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBinding) { +func (self *Gui) keybindingOpts() types.KeybindingsOpts { config := self.c.UserConfig.Keybinding guards := types.KeybindingGuards{ @@ -43,11 +52,18 @@ func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBi NoPopupPanel: self.noPopupPanel, } - opts := types.KeybindingsOpts{ + return types.KeybindingsOpts{ GetKey: keybindings.GetKey, Config: config, Guards: guards, } +} + +// renaming receiver to 'self' to aid refactoring. Will probably end up moving all Gui handlers to this pattern eventually. +func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBinding) { + config := self.c.UserConfig.Keybinding + + opts := self.c.KeybindingsOpts() bindings := []*types.Binding{ { @@ -486,7 +502,7 @@ func (gui *Gui) SetKeybinding(binding *types.Binding) error { if gocui.IsMouseKey(binding.Key) { handler = func() error { // we ignore click events on views that aren't popup panels, when a popup panel is focused - if gui.popupPanelFocused() && gui.currentViewName() != binding.ViewName { + if gui.helpers.Confirmation.IsPopupPanelFocused() && gui.currentViewName() != binding.ViewName { return nil } @@ -502,7 +518,7 @@ func (gui *Gui) SetMouseKeybinding(binding *gocui.ViewMouseBinding) error { baseHandler := binding.Handler newHandler := func(opts gocui.ViewMouseBindingOpts) error { // we ignore click events on views that aren't popup panels, when a popup panel is focused - if gui.popupPanelFocused() && gui.currentViewName() != binding.ViewName { + if gui.helpers.Confirmation.IsPopupPanelFocused() && gui.currentViewName() != binding.ViewName { return nil } |