# HG changeset patch # User Christian Brabandt # Date 1708976704 -3600 # Node ID cffcacc1502a624983d6b866ac63d826864c4654 # Parent 8d14e400cd20906f07a7a826170f16d3610f4bd9 patch 9.1.0137: in cmdline mode doesn't delete composing chars Commit: https://github.com/vim/vim/commit/ff2b79d23956263ab0120623c37e0b4498be01db Author: zeertzjq Date: Mon Feb 26 20:38:36 2024 +0100 patch 9.1.0137: in cmdline mode doesn't delete composing chars Problem: in cmdline mode doesn't delete composing chars Solution: Use mb_head_off() and mb_ptr2len() (zeertzjq) closes: #14095 Signed-off-by: zeertzjq Signed-off-by: Christian Brabandt diff --git a/src/mbyte.c b/src/mbyte.c --- a/src/mbyte.c +++ b/src/mbyte.c @@ -4188,32 +4188,12 @@ mb_copy_char(char_u **fp, char_u **tp) int mb_off_next(char_u *base, char_u *p) { - int i; - int j; - - if (enc_utf8) - { - if (*p < 0x80) // be quick for ASCII - return 0; - - // Find the next character that isn't 10xx.xxxx - for (i = 0; (p[i] & 0xc0) == 0x80; ++i) - ; - if (i > 0) - { - // Check for illegal sequence. - for (j = 0; p - j > base; ++j) - if ((p[-j] & 0xc0) != 0x80) - break; - if (utf8len_tab[p[-j]] != i + j) - return 0; - } - return i; - } - - // Only need to check if we're on a trail byte, it doesn't matter if we - // want the offset to the next or current character. - return (*mb_head_off)(base, p); + int head_off = (*mb_head_off)(base, p); + + if (head_off == 0) + return 0; + + return (*mb_ptr2len)(p - head_off) - head_off; } /* diff --git a/src/testdir/test_cmdline.vim b/src/testdir/test_cmdline.vim --- a/src/testdir/test_cmdline.vim +++ b/src/testdir/test_cmdline.vim @@ -917,6 +917,26 @@ func Test_cmdline_remove_char() let &encoding = encoding_save endfunc +func Test_cmdline_del_utf8() + let @s = '⒌' + call feedkeys(":\"\s,,\\\\", 'tx') + call assert_equal('",,', @:) + + let @s = 'a̳' + call feedkeys(":\"\s,,\\\\", 'tx') + call assert_equal('",,', @:) + + let @s = 'β̳' + call feedkeys(":\"\s,,\\\\", 'tx') + call assert_equal('",,', @:) + + if has('arabic') + let @s = 'لا' + call feedkeys(":\"\s,,\\\\", 'tx') + call assert_equal('",,', @:) + endif +endfunc + func Test_cmdline_keymap_ctrl_hat() CheckFeature keymap diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -705,6 +705,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 137, +/**/ 136, /**/ 135,