Skip to content

Commit 07f0dbe

Browse files
glepnirchrisbra
authored andcommitted
patch 9.1.1121: Enter does not insert newline with "noselect"
Problem: Enter does not insert newline with "noselect" when the pum is visible (lifepillar) Solution: When Enter is pressed and no complete-item is selected, ins_compl_prep returns false, and the edit function continues processing Enter to insert a new line. (glepnir) fixes: #1653 closes: #16653 Signed-off-by: glepnir <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent ee1a24b commit 07f0dbe

5 files changed

Lines changed: 31 additions & 6 deletions

File tree

src/insexpand.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,6 +1889,7 @@ ins_compl_clear(void)
18891889
compl_cont_status = 0;
18901890
compl_started = FALSE;
18911891
compl_matches = 0;
1892+
compl_selected_item = -1;
18921893
compl_ins_end_col = 0;
18931894
VIM_CLEAR_STRING(compl_pattern);
18941895
VIM_CLEAR_STRING(compl_leader);
@@ -2579,6 +2580,10 @@ ins_compl_prep(int c)
25792580
{
25802581
int retval = FALSE;
25812582
int prev_mode = ctrl_x_mode;
2583+
int handle_enter = FALSE;
2584+
2585+
if ((c == CAR || c == NL || c == K_KENTER) && compl_selected_item == -1)
2586+
handle_enter = TRUE;
25822587

25832588
// Forget any previous 'special' messages if this is actually
25842589
// a ^X mode key - bar ^R, in which case we wait to see what it gives us.
@@ -2676,7 +2681,14 @@ ins_compl_prep(int c)
26762681
if ((ctrl_x_mode_normal() && c != Ctrl_N && c != Ctrl_P
26772682
&& c != Ctrl_R && !ins_compl_pum_key(c))
26782683
|| ctrl_x_mode == CTRL_X_FINISHED)
2684+
{
26792685
retval = ins_compl_stop(c, prev_mode, retval);
2686+
// When it is the Enter key and no selected item, return false, and
2687+
// continue processing the Enter key to insert a new line in the
2688+
// edit function.
2689+
if (retval && handle_enter)
2690+
retval = FALSE;
2691+
}
26802692
}
26812693
else if (ctrl_x_mode == CTRL_X_LOCAL_MSG)
26822694
// Trigger the CompleteDone event to give scripts a chance to act

src/testdir/test_edit.vim

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func Test_edit_07()
198198
endif
199199
endfu
200200
au InsertCharPre <buffer> :call DoIt()
201-
call feedkeys("A\<f5>\<c-p>u\<cr>\<c-l>\<cr>", 'tx')
201+
call feedkeys("A\<f5>\<c-p>u\<C-Y>\<c-l>\<cr>", 'tx')
202202
call assert_equal(["Jan\<c-l>",''], 1->getline('$'))
203203
%d
204204
call setline(1, 'J')
@@ -594,7 +594,7 @@ func Test_edit_CTRL_I()
594594
call assert_equal([include, 'two', ''], getline(1, '$'))
595595
call feedkeys("2ggC\<c-x>\<tab>\<down>\<down>\<cr>\<esc>", 'tnix')
596596
call assert_equal([include, 'three', ''], getline(1, '$'))
597-
call feedkeys("2ggC\<c-x>\<tab>\<down>\<down>\<down>\<cr>\<esc>", 'tnix')
597+
call feedkeys("2ggC\<c-x>\<tab>\<down>\<down>\<down>\<C-y>\<esc>", 'tnix')
598598
call assert_equal([include, '', ''], getline(1, '$'))
599599
bw!
600600
endfunc
@@ -622,7 +622,7 @@ func Test_edit_CTRL_K()
622622
%d
623623
call setline(1, 'A')
624624
call cursor(1, 1)
625-
call feedkeys("A\<c-x>\<c-k>\<down>\<down>\<down>\<cr>\<esc>", 'tnix')
625+
call feedkeys("A\<c-x>\<c-k>\<down>\<down>\<down>\<C-Y>\<esc>", 'tnix')
626626
call assert_equal(['A'], getline(1, '$'))
627627
%d
628628
call setline(1, 'A')
@@ -2293,4 +2293,15 @@ func Test_edit_backspace_smarttab_virtual_text()
22932293
set smarttab&
22942294
endfunc
22952295

2296+
func Test_edit_CAR()
2297+
set cot=menu,menuone,noselect
2298+
new
2299+
2300+
call feedkeys("Shello hero\<CR>h\<C-x>\<C-N>e\<CR>", 'tx')
2301+
call assert_equal(['hello hero', 'he', ''], getline(1, '$'))
2302+
2303+
bw!
2304+
set cot&
2305+
endfunc
2306+
22962307
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/test_ins_complete.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2855,7 +2855,7 @@ func Test_complete_fuzzy_match()
28552855
call setline(1, ['Text', 'ToText', ''])
28562856
call cursor(3, 1)
28572857
call feedkeys("STe\<C-X>\<C-N>x\<CR>\<Esc>0", 'tx!')
2858-
call assert_equal('Tex', getline('.'))
2858+
call assert_equal('Tex', getline(line('.') - 1))
28592859

28602860
" test case for nosort option
28612861
set cot=menuone,menu,noinsert,fuzzy,nosort

src/testdir/test_popup.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ func Test_popup_complete_backwards()
987987
call setline(1, ['Post', 'Port', 'Po'])
988988
let expected=['Post', 'Port', 'Port']
989989
call cursor(3,2)
990-
call feedkeys("A\<C-X>". repeat("\<C-P>", 3). "rt\<cr>", 'tx')
990+
call feedkeys("A\<C-X>". repeat("\<C-P>", 3). "rt\<C-Y>", 'tx')
991991
call assert_equal(expected, getline(1,'$'))
992992
bwipe!
993993
endfunc
@@ -997,7 +997,7 @@ func Test_popup_complete_backwards_ctrl_p()
997997
call setline(1, ['Post', 'Port', 'Po'])
998998
let expected=['Post', 'Port', 'Port']
999999
call cursor(3,2)
1000-
call feedkeys("A\<C-P>\<C-N>rt\<cr>", 'tx')
1000+
call feedkeys("A\<C-P>\<C-N>rt\<C-Y>", 'tx')
10011001
call assert_equal(expected, getline(1,'$'))
10021002
bwipe!
10031003
endfunc

src/version.c

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

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
1121,
707709
/**/
708710
1120,
709711
/**/

0 commit comments

Comments
 (0)