Skip to content

Commit 869e352

Browse files
committed
patch 8.0.0041
Problem: When using Insert mode completion but not actually inserting anything an undo item is still created. (Tommy Allen) Solution: Do not call stop_arrow() when not inserting anything.
1 parent 8507747 commit 869e352

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

src/edit.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2799,9 +2799,6 @@ set_completion(colnr_T startcol, list_T *list)
27992799
ins_compl_prep(' ');
28002800
ins_compl_clear();
28012801

2802-
if (stop_arrow() == FAIL)
2803-
return;
2804-
28052802
compl_direction = FORWARD;
28062803
if (startcol > curwin->w_cursor.col)
28072804
startcol = curwin->w_cursor.col;
@@ -3876,7 +3873,8 @@ ins_compl_prep(int c)
38763873
/* put the cursor on the last char, for 'tw' formatting */
38773874
if (prev_col > 0)
38783875
dec_cursor();
3879-
if (stop_arrow() == OK)
3876+
/* only format when something was inserted */
3877+
if (!arrow_used && !ins_need_undo)
38803878
insertchar(NUL, 0, -1);
38813879
if (prev_col > 0
38823880
&& ml_get_curline()[curwin->w_cursor.col] != NUL)

src/testdir/test_popup.vim

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ func DummyCompleteFour(findstart, base)
378378
endif
379379
endfunc
380380

381-
:"Test that 'completefunc' works when it's OK.
381+
" Test that 'completefunc' works when it's OK.
382382
func Test_omnifunc_with_check()
383383
new
384384
setlocal omnifunc=DummyCompleteFour
@@ -400,4 +400,30 @@ func Test_omnifunc_with_check()
400400
q!
401401
endfunc
402402

403+
function UndoComplete()
404+
call complete(1, ['January', 'February', 'March',
405+
\ 'April', 'May', 'June', 'July', 'August', 'September',
406+
\ 'October', 'November', 'December'])
407+
return ''
408+
endfunc
409+
410+
" Test that no undo item is created when no completion is inserted
411+
func Test_complete_no_undo()
412+
set completeopt=menu,preview,noinsert,noselect
413+
inoremap <Right> <C-R>=UndoComplete()<CR>
414+
new
415+
call feedkeys("ixxx\<CR>\<CR>yyy\<Esc>k", 'xt')
416+
call feedkeys("iaaa\<Esc>0", 'xt')
417+
call assert_equal('aaa', getline(2))
418+
call feedkeys("i\<Right>\<Esc>", 'xt')
419+
call assert_equal('aaa', getline(2))
420+
call feedkeys("u", 'xt')
421+
call assert_equal('', getline(2))
422+
423+
iunmap <Right>
424+
set completeopt&
425+
q!
426+
endfunc
427+
428+
403429
" 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+
41,
767769
/**/
768770
40,
769771
/**/

0 commit comments

Comments
 (0)