From: anton Date: Wed, 31 May 2017 06:59:12 +0000 (+0000) Subject: Allow replacement of UTF-8 characters in vi mode. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=cdbe413d912ae36f87ffb8f7b1d7efe3aa9a30b4;p=openbsd Allow replacement of UTF-8 characters in vi mode. Reported by Walter Alejandro Iglesias on tech@. ok schwarze@ tb@ --- diff --git a/bin/ksh/vi.c b/bin/ksh/vi.c index fd6c32507ad..ec8aa9964e8 100644 --- a/bin/ksh/vi.c +++ b/bin/ksh/vi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vi.c,v 1.45 2017/05/28 07:27:01 anton Exp $ */ +/* $OpenBSD: vi.c,v 1.46 2017/05/31 06:59:12 anton Exp $ */ /* * vi command editing @@ -926,13 +926,24 @@ vi_cmd(int argcnt, const char *cmd) if (cmd[1] == 0) vi_error(); else { - int n; - - if (es->cursor + argcnt > es->linelen) + c1 = 0; + for (cur = es->cursor; + cur < es->linelen; cur++) { + if (!isu8cont(es->cbuf[cur])) + c1++; + if (c1 > argcnt) + break; + } + if (argcnt > c1) return -1; - for (n = 0; n < argcnt; ++n) - es->cbuf[es->cursor + n] = cmd[1]; - es->cursor += n - 1; + + del_range(es->cursor, cur); + while (argcnt-- > 0) + putbuf(&cmd[1], 1, 0); + while (es->cursor > 0) + if (!isu8cont(es->cbuf[--es->cursor])) + break; + es->cbuf[es->linelen] = '\0'; } break; diff --git a/regress/bin/ksh/vi/vi.sh b/regress/bin/ksh/vi/vi.sh index 710528a8a85..7a4603ac00e 100644 --- a/regress/bin/ksh/vi/vi.sh +++ b/regress/bin/ksh/vi/vi.sh @@ -134,6 +134,9 @@ testseq "abcdef\00334h2Rxy\0033" " $ abcdef\b\b\b\b\bxyxy\b\r\naxyxyf" # r: Replace character. testseq "abcd\00332h2rxiy" " $ abcd\b\b\bxx\byxd\b\b\r\naxyxd" +testseq "\0303\0266\0033ro" " $ \0303\0266\bo \b\b\r\no" +testseq "\0342\0202\0254\0033ro" " $ \0342\0202\0254\bo \b\b\b\r\no" +testseq "\0303\0266\00332ro" " $ \0303\0266\b\a\r\n\0303\0266" # S: Substitute whole line. testseq "oldst\0033Snew" " $ oldst\b\b\b\b\b \r $ new\r\nnew"