mirror of
https://github.com/zyedidia/micro
synced 2024-09-29 20:54:50 +00:00
Record events in cursor
This commit is contained in:
parent
bbd6f559ab
commit
0283c01432
|
@ -1,7 +1,7 @@
|
|||
package action
|
||||
|
||||
import (
|
||||
"log"
|
||||
"bytes"
|
||||
|
||||
"github.com/zyedidia/tcell"
|
||||
)
|
||||
|
@ -60,8 +60,9 @@ type KeyTree struct {
|
|||
type KeyTreeCursor struct {
|
||||
node *KeyTreeNode
|
||||
|
||||
wildcards []KeyEvent
|
||||
mouseInfo *tcell.EventMouse
|
||||
recordedEvents []Event
|
||||
wildcards []KeyEvent
|
||||
mouseInfo *tcell.EventMouse
|
||||
}
|
||||
|
||||
// MakeClosure uses the information stored in a key tree cursor to construct
|
||||
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue