Let the 's' command delete the right number of bytes when UTF-8
authorschwarze <schwarze@openbsd.org>
Wed, 31 May 2017 20:18:43 +0000 (20:18 +0000)
committerschwarze <schwarze@openbsd.org>
Wed, 31 May 2017 20:18:43 +0000 (20:18 +0000)
characters are involved; similar to what anton@ previously did for 'r';
OK tb@ anton@;
also tested by Walter Alejandro Iglesias <wai at roquesor dot com>.

bin/ksh/vi.c

index ec8aa99..a5f9fb4 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: vi.c,v 1.46 2017/05/31 06:59:12 anton Exp $   */
+/*     $OpenBSD: vi.c,v 1.47 2017/05/31 20:18:43 schwarze Exp $        */
 
 /*
  *     vi command editing
@@ -956,9 +956,11 @@ vi_cmd(int argcnt, const char *cmd)
                        if (es->linelen == 0)
                                return -1;
                        modified = 1; hnum = hlast;
-                       if (es->cursor + argcnt > es->linelen)
-                               argcnt = es->linelen - es->cursor;
-                       del_range(es->cursor, es->cursor + argcnt);
+                       for (cur = es->cursor; cur < es->linelen; cur++)
+                               if (!isu8cont(es->cbuf[cur]))
+                                       if (argcnt-- == 0)
+                                               break;
+                       del_range(es->cursor, cur);
                        insert = INSERT;
                        break;