diff options
author | anton <anton@cvs.openbsd.org> | 2017-05-31 06:59:14 +0000 |
---|---|---|
committer | anton <anton@cvs.openbsd.org> | 2017-05-31 06:59:14 +0000 |
commit | 69ad71c89bfe95f021cf39dabaecf7ba80146d6a (patch) | |
tree | f8c78cc7b4bb0df552eba8c4aaf510186df45fd4 /bin/ksh | |
parent | ecb618331c40c05f9b7c644bd74d2ab04c49f0c3 (diff) |
Allow replacement of UTF-8 characters in vi mode.
Reported by Walter Alejandro Iglesias on tech@.
ok schwarze@ tb@
Diffstat (limited to 'bin/ksh')
-rw-r--r-- | bin/ksh/vi.c | 25 |
1 files changed, 18 insertions, 7 deletions
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; |