Enable registering raw events

Fixes #1821
This commit is contained in:
Zachary Yedidia
2020-08-11 14:36:58 -04:00
parent 1e83e666fb
commit 352f57cf11
3 changed files with 20 additions and 13 deletions

View File

@@ -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) {

View File

@@ -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}
}
}

View File

@@ -5,3 +5,7 @@ const (
)
var Bindings map[string]string
func init() {
Bindings = make(map[string]string)
}