]> git.lizzy.rs Git - micro.git/blobdiff - internal/buffer/eventhandler.go
fix eofnewline not running on files with 1 rune (#1535)
[micro.git] / internal / buffer / eventhandler.go
index 9e57108d064b7643df1dea3d26091aa6113d136f..4e4243a07953488adcf8310ec1104964e1752c3f 100644 (file)
@@ -144,12 +144,12 @@ func (eh *EventHandler) InsertBytes(start Loc, text []byte) {
 
        for _, c := range eh.cursors {
                move := func(loc Loc) Loc {
-                       if start.Y != end.Y && loc.GreaterThan(start) {
+                       if start.Y != loc.Y && loc.GreaterThan(start) {
                                loc.Y += end.Y - start.Y
                        } else if loc.Y == start.Y && loc.GreaterEqual(start) {
                                loc.Y += end.Y - start.Y
                                if lastnl >= 0 {
-                                       loc.X = textX
+                                       loc.X += textX - start.X
                                } else {
                                        loc.X += textX
                                }
@@ -180,7 +180,7 @@ func (eh *EventHandler) Remove(start, end Loc) {
 
        for _, c := range eh.cursors {
                move := func(loc Loc) Loc {
-                       if start.Y != end.Y && loc.GreaterThan(end) {
+                       if loc.Y != end.Y && loc.GreaterThan(end) {
                                loc.Y -= end.Y - start.Y
                        } else if loc.Y == end.Y && loc.GreaterEqual(end) {
                                loc = loc.MoveLA(-DiffLA(start, end, eh.buf.LineArray), eh.buf.LineArray)