chainable actions and flexible modifiers

Doesn't work quite right yet, but the idea is to support
arbitrary modifiers without having to hardcode in all the permutations
of alt/shift/ctrl for every key, along with chainable actions,
so this can be configured:

   "AltBackspace": "SelectWordLeft,Backspace",
This commit is contained in:
JT Olds
2016-06-01 16:06:37 -06:00
parent 9e96623725
commit 646cdd6a9f
2 changed files with 219 additions and 170 deletions

View File

@@ -280,7 +280,7 @@ func (v *View) HandleEvent(event tcell.Event) {
v.Buf.Insert(v.Cursor.Loc(), string(e.Rune()))
v.Cursor.Right()
} else {
for key, action := range bindings {
for key, actions := range bindings {
if e.Key() == key.keyCode {
if e.Key() == tcell.KeyRune {
if e.Rune() != key.r {
@@ -288,12 +288,15 @@ func (v *View) HandleEvent(event tcell.Event) {
}
}
if e.Modifiers() == key.modifiers {
relocate = action(v)
for _, pl := range loadedPlugins {
funcName := strings.Split(runtime.FuncForPC(reflect.ValueOf(action).Pointer()).Name(), ".")
err := Call(pl+"_on"+funcName[len(funcName)-1], nil)
if err != nil && !strings.HasPrefix(err.Error(), "function does not exist") {
TermMessage(err)
relocate = false
for _, action := range actions {
relocate = action(v) || relocate
for _, pl := range loadedPlugins {
funcName := strings.Split(runtime.FuncForPC(reflect.ValueOf(action).Pointer()).Name(), ".")
err := Call(pl+"_on"+funcName[len(funcName)-1], nil)
if err != nil && !strings.HasPrefix(err.Error(), "function does not exist") {
TermMessage(err)
}
}
}
}