tex: move cursor to the first change after undoing :s - neatvi - [fork] simple vi-type editor with UTF-8 support
 (HTM) git clone git://src.adamsgaard.dk/neatvi
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
       ---
 (DIR) commit 54a452c55c89f3f3bc1a58741b81f2471c7a9c18
 (DIR) parent 84fad00b295c1fb13ea3baa0c8267b7aa4b035de
 (HTM) Author: Kyryl Melekhin <k.melekhin@gmail.com>
       Date:   Wed,  3 Mar 2021 11:18:33 +0330
       
       ex: move cursor to the first change after undoing :s
       
       Diffstat:
         M ex.c                                |      12 ++++++++----
       
       1 file changed, 8 insertions(+), 4 deletions(-)
       ---
 (DIR) diff --git a/ex.c b/ex.c
       t@@ -743,8 +743,10 @@ static int ec_substitute(char *ec)
                }
                for (i = beg; i < end; i++) {
                        char *ln = lbuf_get(xb, i);
       -                struct sbuf *r = sbuf_make();
       +                struct sbuf *r = NULL;
                        while (rset_find(re, ln, LEN(offs) / 2, offs, 0) >= 0) {
       +                        if (!r)
       +                                r = sbuf_make();
                                sbuf_mem(r, ln, offs[0]);
                                replace(r, rep, ln, offs);
                                ln += offs[1];
       t@@ -753,9 +755,11 @@ static int ec_substitute(char *ec)
                                if (offs[1] <= 0)        /* zero-length match */
                                        sbuf_chr(r, (unsigned char) *ln++);
                        }
       -                sbuf_str(r, ln);
       -                lbuf_edit(xb, sbuf_buf(r), i, i + 1);
       -                sbuf_free(r);
       +                if (r) {
       +                        sbuf_str(r, ln);
       +                        lbuf_edit(xb, sbuf_buf(r), i, i + 1);
       +                        sbuf_free(r);
       +                }
                }
                rset_free(re);
                free(rep);