0
0
mirror of https://github.com/vim/vim.git synced 2025-09-26 04:04:07 -04:00

patch 9.1.0021: i_CTRL-R- doesn't work for multibyte chars in Replace mode

Problem:  i_CTRL-R- doesn't work for multibyte chars in Replace mode,
          Coverity complains missing return value for u_save_cursor()
Solution: Use mb_charlen() and del_chars() instead, handle failure mode
          for u_save_cursor() correctly (@zeertzjq)

closes: #13846

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
zeertzjq
2024-01-12 17:43:05 +01:00
committed by Christian Brabandt
parent 4f32c83a77
commit 424ec1f235
3 changed files with 19 additions and 4 deletions

View File

@@ -832,8 +832,9 @@ insert_reg(
if ((State & REPLACE_FLAG) != 0) if ((State & REPLACE_FLAG) != 0)
{ {
pos_T curpos; pos_T curpos;
u_save_cursor(); if (u_save_cursor() == FAIL)
del_bytes((long)STRLEN(y_current->y_array[0]), TRUE, FALSE); return FAIL;
del_chars((long)mb_charlen(y_current->y_array[0]), TRUE);
curpos = curwin->w_cursor; curpos = curwin->w_cursor;
if (oneright() == FAIL) if (oneright() == FAIL)
// hit end of line, need to put forward (after the current position) // hit end of line, need to put forward (after the current position)

View File

@@ -963,6 +963,18 @@ func Test_insert_small_delete_replace_mode()
let @- = '' let @- = ''
exe ":norm! R\<C-R>-ZZZ" exe ":norm! R\<C-R>-ZZZ"
call assert_equal(['ZZZ', 'foofoo', '', 'bfoobarZZZZ'], getline(1, 4)) call assert_equal(['ZZZ', 'foofoo', '', 'bfoobarZZZZ'], getline(1, 4))
let @- = 'βbβ'
call cursor(4, 1)
exe ":norm! R\<C-R>-"
call assert_equal(['ZZZ', 'foofoo', '', 'βbβobarZZZZ'], getline(1, 4))
let @- = 'bβb'
call cursor(4, 1)
exe ":norm! R\<C-R>-"
call assert_equal(['ZZZ', 'foofoo', '', 'bβbobarZZZZ'], getline(1, 4))
let @- = 'βbβ'
call cursor(4, 1)
exe ":norm! R\<C-R>-"
call assert_equal(['ZZZ', 'foofoo', '', 'βbβobarZZZZ'], getline(1, 4))
bwipe! bwipe!
endfunc endfunc

View File

@@ -704,6 +704,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
21,
/**/ /**/
20, 20,
/**/ /**/