From 4db7f33eaf00b6390e0292c9f72d358e25c67997 Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Thu, 13 Oct 2016 20:47:33 -0400 Subject: [PATCH] More fixes to search and replace --- cmd/micro/command.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cmd/micro/command.go b/cmd/micro/command.go index b81c0e44..24f8170e 100644 --- a/cmd/micro/command.go +++ b/cmd/micro/command.go @@ -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 } } }