From 6b5805ca82b9eb7aa9f308872a1ad51aae1daa3e Mon Sep 17 00:00:00 2001 From: matthias314 Date: Tue, 21 Jan 2025 12:15:04 -0500 Subject: [PATCH] adjust selection after `replaceall` --- internal/action/command.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/action/command.go b/internal/action/command.go index 211e237c63..07a85cd42f 100644 --- a/internal/action/command.go +++ b/internal/action/command.go @@ -958,7 +958,15 @@ func (h *BufPane) ReplaceCmd(args []string) { searchLoc = start // otherwise me might start at the end } if all { - nreplaced, _ = h.Buf.ReplaceRegex(start, end, regex, replace, !noRegex) + var deltaX int + nreplaced, deltaX = h.Buf.ReplaceRegex(start, end, regex, replace, !noRegex) + if selection { + if start.LessEqual(end) { + h.Cursor.SetSelectionEnd(end.Move(deltaX, h.Buf)) + } else { + h.Cursor.SetSelectionStart(start.Move(deltaX, h.Buf)) + } + } } else { inRange := func(l buffer.Loc) bool { return l.GreaterEqual(start) && l.LessEqual(end)