Skip to content

Commit 5a8d691

Browse files
committed
adjust selection after replaceall
1 parent f5debdf commit 5a8d691

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

internal/action/command.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,17 @@ func (h *BufPane) ReplaceCmd(args []string) {
958958
searchLoc = start // otherwise me might start at the end
959959
}
960960
if all {
961-
nreplaced, _ = h.Buf.ReplaceRegex(start, end, regex, replace, !noRegex)
961+
var deltaX int
962+
nreplaced, deltaX = h.Buf.ReplaceRegex(start, end, regex, replace, !noRegex)
963+
if selection {
964+
if start.LessEqual(end) {
965+
newEnd := end.Move(deltaX, h.Buf)
966+
h.Cursor.SetSelectionEnd(newEnd)
967+
h.Cursor.GotoLoc(newEnd)
968+
} else {
969+
h.Cursor.SetSelectionStart(start.Move(deltaX, h.Buf))
970+
}
971+
}
962972
} else {
963973
inRange := func(l buffer.Loc) bool {
964974
return l.GreaterEqual(start) && l.LessEqual(end)

0 commit comments

Comments
 (0)