summaryrefslogtreecommitdiffstats
path: root/pkg/gui/keybindings.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2022-01-29 19:09:20 +1100
committerJesse Duffield <jessedduffield@gmail.com>2022-03-17 19:13:40 +1100
commit138be04e6575f2bd087630e49d122af578c78bf6 (patch)
treeed038641d6871e49ff426096f300e6b3b3ab4f1e /pkg/gui/keybindings.go
parent1a74ed32143f826104e1d60f4392d2d8ba53cd80 (diff)
refactor contexts code
Diffstat (limited to 'pkg/gui/keybindings.go')
-rw-r--r--pkg/gui/keybindings.go28
1 files changed, 27 insertions, 1 deletions
diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go
index 0e09022c5..b9197d1b4 100644
--- a/pkg/gui/keybindings.go
+++ b/pkg/gui/keybindings.go
@@ -1492,7 +1492,7 @@ func (gui *Gui) keybindings() error {
bindings = append(bindings, gui.GetInitialKeybindings()...)
for _, binding := range bindings {
- if err := gui.g.SetKeybinding(binding.ViewName, binding.Contexts, binding.Key, binding.Modifier, gui.wrappedHandler(binding.Handler)); err != nil {
+ if err := gui.SetKeybinding(binding); err != nil {
return err
}
}
@@ -1508,3 +1508,29 @@ func (gui *Gui) keybindings() error {
return nil
}
+
+func (gui *Gui) wrappedHandler(f func() error) func(g *gocui.Gui, v *gocui.View) error {
+ return func(g *gocui.Gui, v *gocui.View) error {
+ return f()
+ }
+}
+
+func (gui *Gui) SetKeybinding(binding *types.Binding) error {
+ handler := binding.Handler
+ if 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 {
+ return nil
+ }
+
+ return binding.Handler()
+ }
+ }
+
+ return gui.g.SetKeybinding(binding.ViewName, binding.Contexts, binding.Key, binding.Modifier, gui.wrappedHandler(handler))
+}
+
+func isMouseKey(key interface{}) bool {
+ return key == gocui.MouseLeft || key == gocui.MouseRight || key == gocui.MouseMiddle || key == gocui.MouseRelease || key == gocui.MouseWheelUp || key == gocui.MouseWheelDown || key == gocui.MouseWheelLeft || key == gocui.MouseWheelRight
+}