]> git.lizzy.rs Git - micro.git/commitdiff
More fixes to search and replace
authorZachary Yedidia <zyedidia@gmail.com>
Fri, 14 Oct 2016 00:47:33 +0000 (20:47 -0400)
committerZachary Yedidia <zyedidia@gmail.com>
Fri, 14 Oct 2016 00:47:33 +0000 (20:47 -0400)
cmd/micro/command.go

index b81c0e441bac4c0cf771460c67981608d4553363..24f8170eb2759b11647b0699d0e52d3218e5ee68 100644 (file)
@@ -419,23 +419,22 @@ func Replace(args []string) {
                if matches != nil && len(matches) > 0 {
                        prevMatchCount := runePos(matches[0][0], bufStr)
                        searchCount := runePos(matches[0][1], bufStr) - prevMatchCount
-                       adjust := 0
                        prevMatch := matches[0]
                        from := FromCharPos(prevMatch[0], view.Buf)
                        to := from.Move(searchCount, view.Buf)
-                       adjust += Count(replace) - searchCount
+                       adjust := Count(replace) - searchCount
                        view.Buf.Replace(from, to, replace)
                        if len(matches) > 1 {
                                for _, match := range matches[1:] {
                                        found++
                                        matchCount := runePos(match[0], bufStr)
+                                       searchCount = runePos(match[1], bufStr) - matchCount
                                        from = from.Move(matchCount-prevMatchCount+adjust, view.Buf)
-                                       to := from.Move(searchCount, view.Buf)
-                                       // TermMessage(match[0], " ", prevMatch[0], " ", adjust, "\n", from, " ", to)
+                                       to = from.Move(searchCount, view.Buf)
                                        view.Buf.Replace(from, to, replace)
                                        prevMatch = match
                                        prevMatchCount = matchCount
-                                       // adjust += Count(replace) - searchCount
+                                       adjust = Count(replace) - searchCount
                                }
                        }
                }