From 98b6f63b702b82502e0bcd62c3619412848d40f8 Mon Sep 17 00:00:00 2001 From: boombuler Date: Sat, 3 Sep 2016 12:34:57 +0200 Subject: [PATCH] fixes conditional replace before this, conditional replace always replaces the first found occurence of the match not the currenly selected. Might also fix #269 --- cmd/micro/command.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/cmd/micro/command.go b/cmd/micro/command.go index 30ce6c1d..450407be 100644 --- a/cmd/micro/command.go +++ b/cmd/micro/command.go @@ -287,13 +287,8 @@ func Replace(args []string) { view := CurView() found := 0 - for { - match := regex.FindStringIndex(view.Buf.String()) - if match == nil { - break - } - found++ - if strings.Contains(flags, "c") { + if strings.Contains(flags, "c") { + for { // The 'check' flag was used Search(search, view, true) view.Relocate() @@ -308,13 +303,14 @@ func Replace(args []string) { view.Cursor.ResetSelection() } messenger.Reset() - return + break } if choice { view.Cursor.DeleteSelection() - view.Buf.Insert(FromCharPos(match[0], view.Buf), replace) + view.Buf.Insert(view.Cursor.Loc, replace) view.Cursor.ResetSelection() messenger.Reset() + found++ } else { if view.Cursor.HasSelection() { searchStart = ToCharPos(view.Cursor.CurSelection[1], view.Buf) @@ -323,7 +319,14 @@ func Replace(args []string) { } continue } - } else { + } + } else { + for { + match := regex.FindStringIndex(view.Buf.String()) + if match == nil { + break + } + found++ view.Buf.Replace(FromCharPos(match[0], view.Buf), FromCharPos(match[1], view.Buf), replace) } }