mirror of
https://github.com/Hopiu/micro.git
synced 2026-03-16 22:10:26 +00:00
skip empty match right after previous match in ReplaceCmd (#3566)
This commit is contained in:
parent
8cdf68bbf6
commit
aa0fefcaa1
1 changed files with 16 additions and 1 deletions
|
|
@ -950,10 +950,12 @@ func (h *BufPane) ReplaceCmd(args []string) {
|
|||
nreplaced := 0
|
||||
start := h.Buf.Start()
|
||||
end := h.Buf.End()
|
||||
searchLoc := h.Cursor.Loc
|
||||
selection := h.Cursor.HasSelection()
|
||||
if selection {
|
||||
start = h.Cursor.CurSelection[0]
|
||||
end = h.Cursor.CurSelection[1]
|
||||
searchLoc = start // otherwise me might start at the end
|
||||
}
|
||||
if all {
|
||||
nreplaced, _ = h.Buf.ReplaceRegex(start, end, regex, replace, !noRegex)
|
||||
|
|
@ -962,7 +964,7 @@ func (h *BufPane) ReplaceCmd(args []string) {
|
|||
return l.GreaterEqual(start) && l.LessEqual(end)
|
||||
}
|
||||
|
||||
searchLoc := h.Cursor.Loc
|
||||
lastMatchEnd := buffer.Loc{-1, -1}
|
||||
var doReplacement func()
|
||||
doReplacement = func() {
|
||||
locs, found, err := h.Buf.FindNext(search, start, end, searchLoc, true, true)
|
||||
|
|
@ -977,6 +979,18 @@ func (h *BufPane) ReplaceCmd(args []string) {
|
|||
return
|
||||
}
|
||||
|
||||
if lastMatchEnd == locs[1] {
|
||||
// skip empty match right after previous match
|
||||
if searchLoc == end {
|
||||
searchLoc = start
|
||||
lastMatchEnd = buffer.Loc{-1, -1}
|
||||
} else {
|
||||
searchLoc = searchLoc.Move(1, h.Buf)
|
||||
}
|
||||
doReplacement()
|
||||
return
|
||||
}
|
||||
|
||||
h.Cursor.SetSelectionStart(locs[0])
|
||||
h.Cursor.SetSelectionEnd(locs[1])
|
||||
h.GotoLoc(locs[0])
|
||||
|
|
@ -1002,6 +1016,7 @@ func (h *BufPane) ReplaceCmd(args []string) {
|
|||
h.Buf.RelocateCursors()
|
||||
return
|
||||
}
|
||||
lastMatchEnd = searchLoc
|
||||
doReplacement()
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue