[PATCH] vi: fix undo when ':s' replacement string is empty

Denys Vlasenko vda.linux at googlemail.com
Tue Jul 13 13:02:47 UTC 2021


I missed this one, and then this part was rewritten in
"allow regular expressions in ':s' commands".
Sorry about the mess.

On Fri, Jul 2, 2021 at 9:17 AM Ron Yorston <rmy at pobox.com> wrote:
>
> When a ':s' search and replace command had an empty replacement
> string a subsequent undo put the original text in the wrong place.
>
> Fix this by skipping the insertion of an empty replacement string.
>
> function                                             old     new   delta
> colon                                               4024    4036     +12
>
> Signed-off-by: Ron Yorston <rmy at pobox.com>
> ---
>  editors/vi.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/editors/vi.c b/editors/vi.c
> index f0bbc9518..7cbeb7113 100644
> --- a/editors/vi.c
> +++ b/editors/vi.c
> @@ -3139,12 +3139,14 @@ static void colon(char *buf)
>                                         ++lines;
>                                 }
>  #  endif
> -                               // insert the "replace" patern
> -                               bias = string_insert(found, R, ALLOW_UNDO_CHAIN);
> -                               found += bias;
> -                               ls += bias;
> +                               // insert the "replace" pattern, if required
> +                               if (len_R) {
> +                                       bias = string_insert(found, R, ALLOW_UNDO_CHAIN);
> +                                       found += bias;
> +                                       ls += bias;
> +                                       //q += bias; - recalculated anyway
> +                               }
>                                 dot = ls;
> -                               //q += bias; - recalculated anyway
>                                 // check for "global"  :s/foo/bar/g
>                                 if (gflag == 'g') {
>                                         if ((found + len_R) < end_line(ls)) {
> --
> 2.31.1
>
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox


More information about the busybox mailing list