diff options
author | Bram Moolenaar <Bram@vim.org> | 2018-06-28 19:26:28 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2018-06-28 19:26:28 +0200 |
commit | 630afe889a2a02b367ea8eaaa48e66ed81e77ff3 (patch) | |
tree | b842a80b4031b81954a44a68d8e7064722b60e26 /src/ops.c | |
parent | d8b37a53bd29cab78c6997aa75207385213f23e2 (diff) | |
download | vim-git-630afe889a2a02b367ea8eaaa48e66ed81e77ff3.tar.gz |
patch 8.1.0125: virtual edit replace with multi-byte fails at end of linev8.1.0125
Problem: Virtual edit replace with multi-byte fails at end of line. (Lukas
Werling)
Solution: use ins_char() to add the character. (Christian Brabandt,
closes #3114) Rename PCHAR() to PBYTE() to avoid mistakes like
this.
Diffstat (limited to 'src/ops.c')
-rw-r--r-- | src/ops.c | 41 |
1 files changed, 30 insertions, 11 deletions
@@ -2146,6 +2146,25 @@ mb_adjust_opend(oparg_T *oap) #endif #if defined(FEAT_VISUALEXTRA) || defined(PROTO) + +# ifdef FEAT_MBYTE +/* + * Replace the character under the cursor with "c". + * This takes care of multi-byte characters. + */ + static void +replace_character(int c) +{ + int n = State; + + State = REPLACE; + ins_char(c); + State = n; + /* Backup to the replaced character. */ + dec_cursor(); +} + +# endif /* * Replace a whole area with one character. */ @@ -2331,12 +2350,7 @@ op_replace(oparg_T *oap, int c) * with a multi-byte and the other way around. */ if (curwin->w_cursor.lnum == oap->end.lnum) oap->end.col += (*mb_char2len)(c) - (*mb_char2len)(n); - n = State; - State = REPLACE; - ins_char(c); - State = n; - /* Backup to the replaced character. */ - dec_cursor(); + replace_character(c); } else #endif @@ -2358,7 +2372,7 @@ op_replace(oparg_T *oap, int c) getvpos(&oap->end, end_vcol); } #endif - PCHAR(curwin->w_cursor, c); + PBYTE(curwin->w_cursor, c); } } #ifdef FEAT_VIRTUALEDIT @@ -2377,9 +2391,14 @@ op_replace(oparg_T *oap, int c) curwin->w_cursor.col -= (virtcols + 1); for (; virtcols >= 0; virtcols--) { - PCHAR(curwin->w_cursor, c); - if (inc(&curwin->w_cursor) == -1) - break; +#ifdef FEAT_MBYTE + if ((*mb_char2len)(c) > 1) + replace_character(c); + else + #endif + PBYTE(curwin->w_cursor, c); + if (inc(&curwin->w_cursor) == -1) + break; } } #endif @@ -2619,7 +2638,7 @@ swapchar(int op_type, pos_T *pos) } else #endif - PCHAR(*pos, nc); + PBYTE(*pos, nc); return TRUE; } return FALSE; |