command.go: Add some feedback to replace

This commit is contained in:
Camille Scholtz
2016-06-28 19:49:26 +02:00
parent cc9dd00948
commit 24b01776b3

View File

@@ -7,6 +7,7 @@ import (
"os/signal"
"regexp"
"strings"
"strconv"
)
var commands map[string]func([]string)
@@ -143,12 +144,14 @@ func Replace(args []string) {
view := CurView()
found := false
count := 0
for {
match := regex.FindStringIndex(view.Buf.String())
if match == nil {
break
}
found = true
count = count + 1
if strings.Contains(flags, "c") {
// The 'check' flag was used
Search(search, view, true)
@@ -183,7 +186,9 @@ func Replace(args []string) {
view.Buf.Replace(FromCharPos(match[0], view.Buf), FromCharPos(match[1], view.Buf), replace)
}
}
if !found {
if found {
messenger.Message("Replaced " + strconv.Itoa(count) + " occurences")
} else {
messenger.Message("Nothing matched " + search)
}
}