Record events in cursor
package action
import (
- "log"
+ "bytes"
"github.com/zyedidia/tcell"
)
@@ -60,6 +60,7 @@ type KeyTree struct {
type KeyTreeCursor struct {
node *KeyTreeNode
+ recordedEvents []Event
wildcards []KeyEvent
mouseInfo *tcell.EventMouse
}
@@ -176,7 +177,6 @@ func (k *KeyTree) registerBinding(e Event, a TreeAction) {
func (k *KeyTree) NextEvent(e Event, mouse *tcell.EventMouse) (PaneKeyAction, bool) {
n := k.cursor.node
c, ok := n.children[e]
- log.Println("NEXT EVENT", e, len(n.children), ok)
if !ok {
return nil, false
@@ -186,6 +186,8 @@ func (k *KeyTree) NextEvent(e Event, mouse *tcell.EventMouse) (PaneKeyAction, bo
k.cursor.node = c
+ k.cursor.recordedEvents = append(k.cursor.recordedEvents, e)
+
switch ev := e.(type) {
case KeyEvent:
if ev.any {
@@ -221,9 +223,19 @@ func (k *KeyTree) NextEvent(e Event, mouse *tcell.EventMouse) (PaneKeyAction, bo
func (k *KeyTree) ResetEvents() {
k.cursor.node = k.root
k.cursor.wildcards = []KeyEvent{}
+ k.cursor.recordedEvents = []Event{}
k.cursor.mouseInfo = nil
}
+// CurrentEventsStr returns the list of recorded events as a string
+func (k *KeyTree) RecordedEventsStr() string {
+ buf := &bytes.Buffer{}
+ for _, e := range k.cursor.recordedEvents {
+ buf.WriteString(e.Name())
+ }
+ return buf.String()
+}
+
// DeleteBinding removes any currently active actions associated with the
// given event.
func (k *KeyTree) DeleteBinding(e Event) {
