From 88d8b0b1817659b9afdddaf6a039d60c3d4b084c Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Fri, 2 Mar 2018 19:32:23 -0500 Subject: [PATCH] Count replacements in replaceall correctly Fixes #1055 --- cmd/micro/command.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/micro/command.go b/cmd/micro/command.go index 9cbd3259..89f2d22f 100644 --- a/cmd/micro/command.go +++ b/cmd/micro/command.go @@ -590,13 +590,15 @@ func Replace(args []string) { replaceAll := func() { var deltas []Delta for i := 0; i < view.Buf.LinesNum(); i++ { - newText := regex.ReplaceAll(view.Buf.lines[i].data, replaceBytes) + newText := regex.ReplaceAllFunc(view.Buf.lines[i].data, func(in []byte) []byte { + found++ + return replaceBytes + }) from := Loc{0, i} to := Loc{utf8.RuneCount(view.Buf.lines[i].data), i} deltas = append(deltas, Delta{string(newText), from, to}) - found++ } view.Buf.MultipleReplace(deltas) }