diff --git a/internal/action/bindings.go b/internal/action/bindings.go index bae80f63..b3976c79 100644 --- a/internal/action/bindings.go +++ b/internal/action/bindings.go @@ -30,8 +30,6 @@ func createBindingsIfNotExist(fname string) { // InitBindings intializes the bindings map by reading from bindings.json func InitBindings() { - config.Bindings = DefaultBindings("buffer") - var parsed map[string]interface{} filename := filepath.Join(config.ConfigDir, "bindings.json") @@ -50,6 +48,14 @@ func InitBindings() { } } + for p, bind := range Binder { + defaults := DefaultBindings(p) + + for k, v := range defaults { + BindKey(k, v, bind) + } + } + for k, v := range parsed { switch val := v.(type) { case string: @@ -68,22 +74,17 @@ func InitBindings() { screen.TermMessage("Error reading bindings.json: non-string and non-map entry", k) } } - - for p, bind := range Binder { - defaults := DefaultBindings(p) - - for k, v := range defaults { - BindKey(k, v, bind) - } - } } func BindKey(k, v string, bind func(e Event, a string)) { event, err := findEvent(k) if err != nil { screen.TermMessage(err) + return } + config.Bindings[event.Name()] = v + bind(event, v) // switch e := event.(type) { diff --git a/internal/action/keytree.go b/internal/action/keytree.go index 32a86072..5b19640e 100644 --- a/internal/action/keytree.go +++ b/internal/action/keytree.go @@ -141,13 +141,14 @@ func (k *KeyTree) RegisterMouseBinding(e Event, a PaneMouseAction) { func (k *KeyTree) registerBinding(e Event, a TreeAction) { switch ev := e.(type) { - case KeyEvent, MouseEvent: + case KeyEvent, MouseEvent, RawEvent: newNode, ok := k.root.children[e] if !ok { newNode = NewKeyTreeNode() k.root.children[e] = newNode } - newNode.actions = append(newNode.actions, a) + // newNode.actions = append(newNode.actions, a) + newNode.actions = []TreeAction{a} case KeySequenceEvent: n := k.root for _, key := range ev.keys { @@ -159,7 +160,8 @@ func (k *KeyTree) registerBinding(e Event, a TreeAction) { n = newNode } - n.actions = append(n.actions, a) + // n.actions = append(n.actions, a) + n.actions = []TreeAction{a} } } diff --git a/internal/config/globals.go b/internal/config/globals.go index b1dacd2c..f473393a 100644 --- a/internal/config/globals.go +++ b/internal/config/globals.go @@ -5,3 +5,7 @@ const ( ) var Bindings map[string]string + +func init() { + Bindings = make(map[string]string) +}