// 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")
}
}
+ 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:
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) {
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 {
n = newNode
}
- n.actions = append(n.actions, a)
+ // n.actions = append(n.actions, a)
+ n.actions = []TreeAction{a}
}
}