mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-17 14:27:12 +09:00
Small improvement for replace command
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user