mirror of
https://github.com/zyedidia/micro.git
synced 2025-06-18 14:55:38 -04:00
Record events in cursor
This commit is contained in:
parent
bbd6f559ab
commit
0283c01432
@ -1,7 +1,7 @@
|
|||||||
package action
|
package action
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"bytes"
|
||||||
|
|
||||||
"github.com/zyedidia/tcell"
|
"github.com/zyedidia/tcell"
|
||||||
)
|
)
|
||||||
@ -60,8 +60,9 @@ type KeyTree struct {
|
|||||||
type KeyTreeCursor struct {
|
type KeyTreeCursor struct {
|
||||||
node *KeyTreeNode
|
node *KeyTreeNode
|
||||||
|
|
||||||
wildcards []KeyEvent
|
recordedEvents []Event
|
||||||
mouseInfo *tcell.EventMouse
|
wildcards []KeyEvent
|
||||||
|
mouseInfo *tcell.EventMouse
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakeClosure uses the information stored in a key tree cursor to construct
|
// 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) {
|
func (k *KeyTree) NextEvent(e Event, mouse *tcell.EventMouse) (PaneKeyAction, bool) {
|
||||||
n := k.cursor.node
|
n := k.cursor.node
|
||||||
c, ok := n.children[e]
|
c, ok := n.children[e]
|
||||||
log.Println("NEXT EVENT", e, len(n.children), ok)
|
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, false
|
return nil, false
|
||||||
@ -186,6 +186,8 @@ func (k *KeyTree) NextEvent(e Event, mouse *tcell.EventMouse) (PaneKeyAction, bo
|
|||||||
|
|
||||||
k.cursor.node = c
|
k.cursor.node = c
|
||||||
|
|
||||||
|
k.cursor.recordedEvents = append(k.cursor.recordedEvents, e)
|
||||||
|
|
||||||
switch ev := e.(type) {
|
switch ev := e.(type) {
|
||||||
case KeyEvent:
|
case KeyEvent:
|
||||||
if ev.any {
|
if ev.any {
|
||||||
@ -221,9 +223,19 @@ func (k *KeyTree) NextEvent(e Event, mouse *tcell.EventMouse) (PaneKeyAction, bo
|
|||||||
func (k *KeyTree) ResetEvents() {
|
func (k *KeyTree) ResetEvents() {
|
||||||
k.cursor.node = k.root
|
k.cursor.node = k.root
|
||||||
k.cursor.wildcards = []KeyEvent{}
|
k.cursor.wildcards = []KeyEvent{}
|
||||||
|
k.cursor.recordedEvents = []Event{}
|
||||||
k.cursor.mouseInfo = nil
|
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
|
// DeleteBinding removes any currently active actions associated with the
|
||||||
// given event.
|
// given event.
|
||||||
func (k *KeyTree) DeleteBinding(e Event) {
|
func (k *KeyTree) DeleteBinding(e Event) {
|
||||||
|
Loading…
Reference in New Issue
Block a user