Skip to content

Commit d56a79d

Browse files
committed
patch 8.0.0341: undo does not work properly when using completion
Problem: When using complete() and typing a character undo is saved after the character was inserted. (Shougo) Solution: Save for undo before inserting the character.
1 parent 5acff71 commit d56a79d

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

src/edit.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3583,7 +3583,11 @@ ins_compl_addleader(int c)
35833583
{
35843584
#ifdef FEAT_MBYTE
35853585
int cc;
3586+
#endif
35863587

3588+
if (stop_arrow() == FAIL)
3589+
return;
3590+
#ifdef FEAT_MBYTE
35873591
if (has_mbyte && (cc = (*mb_char2len)(c)) > 1)
35883592
{
35893593
char_u buf[MB_MAXBYTES + 1];

src/testdir/test_popup.vim

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,4 +531,24 @@ func Test_completion_respect_bs_option()
531531
bw!
532532
endfunc
533533

534+
func CompleteUndo() abort
535+
call complete(1, g:months)
536+
return ''
537+
endfunc
538+
539+
func Test_completion_can_undo()
540+
inoremap <Right> <c-r>=CompleteUndo()<cr>
541+
set completeopt+=noinsert,noselect
542+
543+
new
544+
call feedkeys("a\<Right>a\<Esc>", 'xt')
545+
call assert_equal('a', getline(1))
546+
undo
547+
call assert_equal('', getline(1))
548+
549+
bwipe!
550+
set completeopt&
551+
iunmap <Right>
552+
endfunc
553+
534554
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
341,
767769
/**/
768770
340,
769771
/**/

0 commit comments

Comments
 (0)