From 5a8d69127793df98762ae3532355cffc3cdeeed6 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 | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/action/command.go b/internal/action/command.go index 211e237c63..8c6d5d714a 100644 --- a/internal/action/command.go +++ b/internal/action/command.go @@ -958,7 +958,17 @@ 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) { + newEnd := end.Move(deltaX, h.Buf) + h.Cursor.SetSelectionEnd(newEnd) + h.Cursor.GotoLoc(newEnd) + } else { + h.Cursor.SetSelectionStart(start.Move(deltaX, h.Buf)) + } + } } else { inRange := func(l buffer.Loc) bool { return l.GreaterEqual(start) && l.LessEqual(end)