From 553b3d80c4ed89e454df895427a154607a6e1a8f Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Sat, 11 Jun 2016 11:23:05 -0400 Subject: [PATCH] Fix diff remove problem in ApplyDiff The location counter was being updated when there was a removal in the text but it shouldn't be. Fixes #163 --- cmd/micro/eventhandler.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cmd/micro/eventhandler.go b/cmd/micro/eventhandler.go index 0a6658da..eed62484 100644 --- a/cmd/micro/eventhandler.go +++ b/cmd/micro/eventhandler.go @@ -66,12 +66,14 @@ func (eh *EventHandler) ApplyDiff(new string) { diff := differ.DiffMain(eh.buf.String(), new, false) loc := eh.buf.Start() for _, d := range diff { - if d.Type == dmp.DiffInsert { - eh.Insert(loc, d.Text) - } else if d.Type == dmp.DiffDelete { + if d.Type == dmp.DiffDelete { eh.Remove(loc, loc.Move(Count(d.Text), eh.buf)) + } else { + if d.Type == dmp.DiffInsert { + eh.Insert(loc, d.Text) + } + loc = loc.Move(Count(d.Text), eh.buf) } - loc = loc.Move(Count(d.Text), eh.buf) } }