diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2019-11-16 12:40:53 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2019-11-21 22:07:14 +1100 |
commit | 44bbc106a9668b8886f22812651635ec00a156fa (patch) | |
tree | f12eca19418f2e2bd87eda7cdf8e272de5033dff /vendor/github.com | |
parent | e6be849eb2f01861ad29caa92595f32c2854bfb0 (diff) |
bump gocui to get contexts on keybindings
Diffstat (limited to 'vendor/github.com')
-rw-r--r-- | vendor/github.com/jesseduffield/gocui/gui.go | 4 | ||||
-rw-r--r-- | vendor/github.com/jesseduffield/gocui/keybinding.go | 20 | ||||
-rw-r--r-- | vendor/github.com/jesseduffield/gocui/view.go | 2 |
3 files changed, 21 insertions, 5 deletions
diff --git a/vendor/github.com/jesseduffield/gocui/gui.go b/vendor/github.com/jesseduffield/gocui/gui.go index 970ef48f9..cbb3ac713 100644 --- a/vendor/github.com/jesseduffield/gocui/gui.go +++ b/vendor/github.com/jesseduffield/gocui/gui.go @@ -295,14 +295,14 @@ func (g *Gui) CurrentView() *View { // SetKeybinding creates a new keybinding. If viewname equals to "" // (empty string) then the keybinding will apply to all views. key must // be a rune or a Key. -func (g *Gui) SetKeybinding(viewname string, key interface{}, mod Modifier, handler func(*Gui, *View) error) error { +func (g *Gui) SetKeybinding(viewname string, contexts []string, key interface{}, mod Modifier, handler func(*Gui, *View) error) error { var kb *keybinding k, ch, err := getKey(key) if err != nil { return err } - kb = newKeybinding(viewname, k, ch, mod, handler) + kb = newKeybinding(viewname, contexts, k, ch, mod, handler) g.keybindings = append(g.keybindings, kb) return nil } diff --git a/vendor/github.com/jesseduffield/gocui/keybinding.go b/vendor/github.com/jesseduffield/gocui/keybinding.go index 6b40a66a5..d3b8904c8 100644 --- a/vendor/github.com/jesseduffield/gocui/keybinding.go +++ b/vendor/github.com/jesseduffield/gocui/keybinding.go @@ -9,6 +9,7 @@ import "github.com/jesseduffield/termbox-go" // Keybidings are used to link a given key-press event with a handler. type keybinding struct { viewName string + contexts []string key Key ch rune mod Modifier @@ -16,9 +17,10 @@ type keybinding struct { } // newKeybinding returns a new Keybinding object. -func newKeybinding(viewname string, key Key, ch rune, mod Modifier, handler func(*Gui, *View) error) (kb *keybinding) { +func newKeybinding(viewname string, contexts []string, key Key, ch rune, mod Modifier, handler func(*Gui, *View) error) (kb *keybinding) { kb = &keybinding{ viewName: viewname, + contexts: contexts, key: key, ch: ch, mod: mod, @@ -32,7 +34,7 @@ func (kb *keybinding) matchKeypress(key Key, ch rune, mod Modifier) bool { return kb.key == key && kb.ch == ch && kb.mod == mod } -// matchView returns if the keybinding matches the current view. +// matchView returns if the keybinding matches the current view (and the view's context) func (kb *keybinding) matchView(v *View) bool { // if the user is typing in a field, ignore char keys if v == nil { @@ -41,7 +43,19 @@ func (kb *keybinding) matchView(v *View) bool { if v.Editable == true && kb.ch != 0 { return false } - return kb.viewName == v.name + if kb.viewName != v.name { + return false + } + // if the keybinding doesn't specify contexts, it applies for all contexts + if len(kb.contexts) == 0 { + return true + } + for _, context := range kb.contexts { + if context == v.Context { + return true + } + } + return false } // Key represents special keys or keys combinations. diff --git a/vendor/github.com/jesseduffield/gocui/view.go b/vendor/github.com/jesseduffield/gocui/view.go index 7dbe1519a..3ce0db552 100644 --- a/vendor/github.com/jesseduffield/gocui/view.go +++ b/vendor/github.com/jesseduffield/gocui/view.go @@ -103,6 +103,8 @@ type View struct { // ParentView is the view which catches events bubbled up from the given view if there's no matching handler ParentView *View + + Context string // this is for assigning keybindings to a view only in certain contexts } type viewLine struct { |