]> git.lizzy.rs Git - micro.git/commitdiff
Fix diff remove problem in ApplyDiff
authorZachary Yedidia <zyedidia@gmail.com>
Sat, 11 Jun 2016 15:23:05 +0000 (11:23 -0400)
committerZachary Yedidia <zyedidia@gmail.com>
Sat, 11 Jun 2016 15:23:05 +0000 (11:23 -0400)
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

index 0a6658daae6e19752be9ea3d9ee2ba0499a692e7..eed62484b374bd2adeb8b788b77226f4de823e84 100644 (file)
@@ -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)
        }
 }