diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-12-15 21:08:50 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-12-15 21:08:50 +0000 |
commit | 8ee6028de3daa9af9e5f90fa9e583ff407bee04f (patch) | |
tree | 802df3b7c109d294fc3232dae7b5eda8f07104aa | |
parent | 427f065a885629db430dd06ccda8b1318b8a5e92 (diff) | |
download | vim-git-8ee6028de3daa9af9e5f90fa9e583ff407bee04f.tar.gz |
patch 8.2.3820: "vrc" does not replace composing charactersv8.2.3820
Problem: "vrc" does not replace composing characters, while "rc" does.
Solution: Check the byte length including composing characters.
(closes #9351)
-rw-r--r-- | src/ops.c | 7 | ||||
-rw-r--r-- | src/testdir/test_visual.vim | 4 | ||||
-rw-r--r-- | src/version.c | 2 |
3 files changed, 11 insertions, 2 deletions
@@ -1162,12 +1162,15 @@ op_replace(oparg_T *oap, int c) n = gchar_cursor(); if (n != NUL) { - if ((*mb_char2len)(c) > 1 || (*mb_char2len)(n) > 1) + int new_byte_len = (*mb_char2len)(c); + int old_byte_len = mb_ptr2len(ml_get_cursor()); + + if (new_byte_len > 1 || old_byte_len > 1) { // This is slow, but it handles replacing a single-byte // 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); + oap->end.col += new_byte_len - old_byte_len; replace_character(c); } else diff --git a/src/testdir/test_visual.vim b/src/testdir/test_visual.vim index 0c89dbb01..ed8efc5de 100644 --- a/src/testdir/test_visual.vim +++ b/src/testdir/test_visual.vim @@ -234,6 +234,10 @@ func Test_virtual_replace() call assert_equal("\txaaaa", getline(1)) set softtabstop& + call setline(1, "xã̳x") + normal gg0lvrb + call assert_equal("xbx", getline(1)) + enew! set noai bs&vim if exists('save_t_kD') diff --git a/src/version.c b/src/version.c index f29571e87..cde6b4d7c 100644 --- a/src/version.c +++ b/src/version.c @@ -750,6 +750,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 3820, +/**/ 3819, /**/ 3818, |