From efb4b5e8996b9ecdb20ca7c0da796b465bccf7e3 Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Sun, 1 May 2016 16:45:23 -0400 Subject: [PATCH] Don't store buffer in text event --- cmd/micro/eventhandler.go | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/cmd/micro/eventhandler.go b/cmd/micro/eventhandler.go index c54319eb..a19cf7e7 100644 --- a/cmd/micro/eventhandler.go +++ b/cmd/micro/eventhandler.go @@ -21,23 +21,22 @@ type TextEvent struct { text string start int end int - buf *Buffer time time.Time } // ExecuteTextEvent runs a text event -func ExecuteTextEvent(t *TextEvent) { +func ExecuteTextEvent(t *TextEvent, buf *Buffer) { if t.eventType == TextEventInsert { - t.buf.Insert(t.start, t.text) + buf.Insert(t.start, t.text) } else if t.eventType == TextEventRemove { - t.text = t.buf.Remove(t.start, t.end) + t.text = buf.Remove(t.start, t.end) } } // UndoTextEvent undoes a text event -func UndoTextEvent(t *TextEvent) { +func UndoTextEvent(t *TextEvent, buf *Buffer) { t.eventType = -t.eventType - ExecuteTextEvent(t) + ExecuteTextEvent(t, buf) } // EventHandler executes text manipulations and allows undoing and redoing @@ -64,7 +63,6 @@ func (eh *EventHandler) Insert(start int, text string) { text: text, start: start, end: start + Count(text), - buf: eh.v.buf, time: time.Now(), } eh.Execute(e) @@ -77,7 +75,6 @@ func (eh *EventHandler) Remove(start, end int) { eventType: TextEventRemove, start: start, end: end, - buf: eh.v.buf, time: time.Now(), } eh.Execute(e) @@ -95,7 +92,7 @@ func (eh *EventHandler) Execute(t *TextEvent) { eh.redo = new(Stack) } eh.undo.Push(t) - ExecuteTextEvent(t) + ExecuteTextEvent(t, eh.v.buf) } // Undo the first event in the undo stack @@ -138,7 +135,7 @@ func (eh *EventHandler) UndoOneEvent() { te := t.(*TextEvent) // Undo it // Modifies the text event - UndoTextEvent(te) + UndoTextEvent(te, eh.v.buf) // Set the cursor in the right place teCursor := te.c @@ -186,7 +183,7 @@ func (eh *EventHandler) RedoOneEvent() { te := t.(*TextEvent) // Modifies the text event - UndoTextEvent(te) + UndoTextEvent(te, eh.v.buf) teCursor := te.c te.c = eh.v.cursor