Small improvement for replace command

This commit is contained in:
Zachary Yedidia
2019-08-11 14:50:28 -07:00
parent ac3a5154c0
commit 5b18edf865
3 changed files with 24 additions and 13 deletions

View File

@@ -60,7 +60,7 @@ func BindKey(k, v string) {
config.Bindings[k] = v
}
// findKeyEvent will find binding Key 'b' using string 'k'
// findEvent will find binding Key 'b' using string 'k'
func findEvent(k string) (b Event, ok bool) {
modifiers := tcell.ModNone

View File

@@ -743,28 +743,35 @@ func (h *BufPane) ReplaceCmd(args []string) {
all := false
noRegex := false
if len(args) > 2 {
for _, arg := range args[2:] {
switch arg {
case "-a":
all = true
case "-l":
noRegex = true
default:
foundSearch := false
foundReplace := false
var search string
var replaceStr string
for _, arg := range args {
switch arg {
case "-a":
all = true
case "-l":
noRegex = true
default:
if !foundSearch {
foundSearch = true
search = arg
} else if !foundReplace {
foundReplace = true
replaceStr = arg
} else {
InfoBar.Error("Invalid flag: " + arg)
return
}
}
}
search := args[0]
if noRegex {
search = regexp.QuoteMeta(search)
}
replace := []byte(args[1])
replaceStr := args[1]
replace := []byte(replaceStr)
var regex *regexp.Regexp
var err error

View File

@@ -407,3 +407,7 @@ func Clamp(val, min, max int) int {
func IsNonAlphaNumeric(c rune) bool {
return !unicode.IsLetter(c) && !unicode.IsNumber(c)
}
func ParseSpecial(s string) string {
return strings.Replace(s, "\\t", "\t", -1)
}