]> git.lizzy.rs Git - micro.git/blobdiff - cmd/micro/eventhandler.go
Fix some issues with unicode handling
[micro.git] / cmd / micro / eventhandler.go
index fee42b5a56abd9ff0a6062057387c4cb9f1f62bb..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)
        }
 }
 
@@ -82,10 +84,10 @@ func (eh *EventHandler) Insert(start Loc, text string) {
                EventType: TextEventInsert,
                Text:      text,
                Start:     start,
-               End:       start.Move(Count(text), eh.buf),
                Time:      time.Now(),
        }
        eh.Execute(e)
+       e.End = start.Move(Count(text), eh.buf)
 }
 
 // Remove creates a remove text event and executes it