Skip to content

Commit 4724728

Browse files
committed
patch 7.4.2146
Problem: Not enough testing for popup menu. CTRL-E does not always work properly. Solution: Add more tests. When using CTRL-E check if the popup menu is visible. (Christian Brabandt)
1 parent 86f2cd5 commit 4724728

4 files changed

Lines changed: 213 additions & 8 deletions

File tree

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ addons:
6262
- python3-dev
6363
- liblua5.1-0-dev
6464
- lua5.1
65+
- cscope
6566

6667
before_install:
6768
- pip install --user cpp-coveralls

src/edit.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3891,8 +3891,9 @@ ins_compl_prep(int c)
38913891
&& pum_visible())
38923892
retval = TRUE;
38933893

3894-
/* CTRL-E means completion is Ended, go back to the typed text. */
3895-
if (c == Ctrl_E)
3894+
/* CTRL-E means completion is Ended, go back to the typed text.
3895+
* but only do this, if the Popup is still visible */
3896+
if (c == Ctrl_E && pum_visible())
38963897
{
38973898
ins_compl_delete();
38983899
if (compl_leader != NULL)

src/testdir/test_popup.vim

Lines changed: 207 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,232 @@
33
let g:months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
44
let g:setting = ''
55

6-
func ListMonths()
7-
if g:setting != ''
8-
exe ":set" g:setting
9-
endif
10-
call complete(col('.'), g:months)
11-
return ''
6+
func! ListMonths()
7+
if g:setting != ''
8+
exe ":set" g:setting
9+
endif
10+
let mth=copy(g:months)
11+
let entered = strcharpart(getline('.'),0,col('.'))
12+
if !empty(entered)
13+
let mth=filter(mth, 'v:val=~"^".entered')
14+
endif
15+
call complete(1, mth)
16+
return ''
1217
endfunc
1318

19+
func! Test_popup_complete()
20+
new
21+
inoremap <f5> <c-r>=ListMonths()<cr>
22+
23+
" <C-E> - select original typed text before the completion started
24+
call feedkeys("aJu\<f5>\<down>\<c-e>\<esc>", 'tx')
25+
call assert_equal(["Ju"], getline(1,2))
26+
%d
27+
28+
" <C-Y> - accept current match
29+
call feedkeys("a\<f5>". repeat("\<down>",7). "\<c-y>\<esc>", 'tx')
30+
call assert_equal(["August"], getline(1,2))
31+
%d
32+
33+
" <BS> - Delete one character from the inserted text (state: 1)
34+
" TODO: This should not end the completion, but it does.
35+
" This should according to the documentation:
36+
" January
37+
" but instead, this does
38+
" Januar
39+
" (idea is, C-L inserts the match from the popup menu
40+
" but if the menu is closed, it will insert the character <c-l>
41+
call feedkeys("aJ\<f5>\<bs>\<c-l>\<esc>", 'tx')
42+
call assert_equal(["Januar "], getline(1,2))
43+
%d
44+
45+
" any-non special character: Stop completion without changing the match
46+
" and insert the typed character
47+
call feedkeys("a\<f5>20", 'tx')
48+
call assert_equal(["January20"], getline(1,2))
49+
%d
50+
51+
" any-non printable, non-white character: Add this character and
52+
" reduce number of matches
53+
call feedkeys("aJu\<f5>\<c-p>l\<c-y>", 'tx')
54+
call assert_equal(["Jul"], getline(1,2))
55+
%d
56+
57+
" any-non printable, non-white character: Add this character and
58+
" reduce number of matches
59+
call feedkeys("aJu\<f5>\<c-p>l\<c-n>\<c-y>", 'tx')
60+
call assert_equal(["July"], getline(1,2))
61+
%d
62+
63+
" any-non printable, non-white character: Add this character and
64+
" reduce number of matches
65+
call feedkeys("aJu\<f5>\<c-p>l\<c-e>", 'tx')
66+
call assert_equal(["Jul"], getline(1,2))
67+
%d
68+
69+
" <BS> - Delete one character from the inserted text (state: 2)
70+
call feedkeys("a\<f5>\<c-n>\<bs>", 'tx')
71+
call assert_equal(["Februar"], getline(1,2))
72+
%d
73+
74+
" <c-l> - Insert one character from the current match
75+
call feedkeys("aJ\<f5>".repeat("\<c-n>",3)."\<c-l>\<esc>", 'tx')
76+
call assert_equal(["J "], getline(1,2))
77+
%d
78+
79+
" <c-l> - Insert one character from the current match
80+
call feedkeys("aJ\<f5>".repeat("\<c-n>",4)."\<c-l>\<esc>", 'tx')
81+
call assert_equal(["January "], getline(1,2))
82+
%d
83+
84+
" <c-y> - Accept current selected match
85+
call feedkeys("aJ\<f5>\<c-y>\<esc>", 'tx')
86+
call assert_equal(["January"], getline(1,2))
87+
%d
88+
89+
" <c-e> - End completion, go back to what was there before selecting a match
90+
call feedkeys("aJu\<f5>\<c-e>\<esc>", 'tx')
91+
call assert_equal(["Ju"], getline(1,2))
92+
%d
93+
94+
" <PageUp> - Select a match several entries back
95+
call feedkeys("a\<f5>\<PageUp>\<c-y>\<esc>", 'tx')
96+
call assert_equal([""], getline(1,2))
97+
%d
98+
99+
" <PageUp><PageUp> - Select a match several entries back
100+
call feedkeys("a\<f5>\<PageUp>\<PageUp>\<c-y>\<esc>", 'tx')
101+
call assert_equal(["December"], getline(1,2))
102+
%d
103+
104+
" <PageUp><PageUp><PageUp> - Select a match several entries back
105+
call feedkeys("a\<f5>\<PageUp>\<PageUp>\<PageUp>\<c-y>\<esc>", 'tx')
106+
call assert_equal(["February"], getline(1,2))
107+
%d
108+
109+
" <PageDown> - Select a match several entries further
110+
call feedkeys("a\<f5>\<PageDown>\<c-y>\<esc>", 'tx')
111+
call assert_equal(["November"], getline(1,2))
112+
%d
113+
114+
" <PageDown><PageDown> - Select a match several entries further
115+
call feedkeys("a\<f5>\<PageDown>\<PageDown>\<c-y>\<esc>", 'tx')
116+
call assert_equal(["December"], getline(1,2))
117+
%d
118+
119+
" <PageDown><PageDown><PageDown> - Select a match several entries further
120+
call feedkeys("a\<f5>\<PageDown>\<PageDown>\<PageDown>\<c-y>\<esc>", 'tx')
121+
call assert_equal([""], getline(1,2))
122+
%d
123+
124+
" <PageDown><PageDown><PageDown><PageDown> - Select a match several entries further
125+
call feedkeys("a\<f5>".repeat("\<PageDown>",4)."\<c-y>\<esc>", 'tx')
126+
call assert_equal(["October"], getline(1,2))
127+
%d
128+
129+
" <Up> - Select a match don't insert yet
130+
call feedkeys("a\<f5>\<Up>\<c-y>\<esc>", 'tx')
131+
call assert_equal([""], getline(1,2))
132+
%d
133+
134+
" <Up><Up> - Select a match don't insert yet
135+
call feedkeys("a\<f5>\<Up>\<Up>\<c-y>\<esc>", 'tx')
136+
call assert_equal(["December"], getline(1,2))
137+
%d
138+
139+
" <Up><Up><Up> - Select a match don't insert yet
140+
call feedkeys("a\<f5>\<Up>\<Up>\<Up>\<c-y>\<esc>", 'tx')
141+
call assert_equal(["November"], getline(1,2))
142+
%d
143+
144+
" <Tab> - Stop completion and insert the match
145+
call feedkeys("a\<f5>\<Tab>\<c-y>\<esc>", 'tx')
146+
call assert_equal(["January "], getline(1,2))
147+
%d
148+
149+
" <Space> - Stop completion and insert the match
150+
call feedkeys("a\<f5>".repeat("\<c-p>",5)." \<esc>", 'tx')
151+
call assert_equal(["September "], getline(1,2))
152+
%d
153+
154+
" <Enter> - Use the text and insert line break (state: 1)
155+
call feedkeys("a\<f5>\<enter>\<esc>", 'tx')
156+
call assert_equal(["January", ''], getline(1,2))
157+
%d
158+
159+
" <Enter> - Insert the current selected text (state: 2)
160+
call feedkeys("a\<f5>".repeat("\<Up>",5)."\<enter>\<esc>", 'tx')
161+
call assert_equal(["September"], getline(1,2))
162+
%d
163+
164+
" Insert match immediately, if there is only one match
165+
" <c-y> selects a character from the line above
166+
call append(0, ["December2015"])
167+
call feedkeys("aD\<f5>\<C-Y>\<C-Y>\<C-Y>\<C-Y>\<enter>\<esc>", 'tx')
168+
call assert_equal(["December2015", "December2015", ""], getline(1,3))
169+
%d
170+
171+
" Insert match immediately, if there is only one match
172+
" <c-e> Should select a character from the line below
173+
call append(1, ["December2015"])
174+
:1
175+
call feedkeys("aD\<f5>\<C-E>\<C-E>\<C-E>\<C-E>\<enter>\<esc>", 'tx')
176+
call assert_equal(["December2015", "", "December2015"], getline(1,3))
177+
%d
178+
179+
" use menuone for 'completeopt'
180+
" Since for the first <c-y> the menu is still shown, will only select
181+
" three letters from the line above
182+
set completeopt&vim
183+
set completeopt+=menuone
184+
call append(0, ["December2015"])
185+
call feedkeys("aD\<f5>\<C-Y>\<C-Y>\<C-Y>\<C-Y>\<enter>\<esc>", 'tx')
186+
call assert_equal(["December2015", "December201", ""], getline(1,3))
187+
%d
188+
189+
" use longest for 'completeopt'
190+
set completeopt&vim
191+
call feedkeys("aM\<f5>\<C-N>\<C-P>\<c-e>\<enter>\<esc>", 'tx')
192+
set completeopt+=longest
193+
call feedkeys("aM\<f5>\<C-N>\<C-P>\<c-e>\<enter>\<esc>", 'tx')
194+
call assert_equal(["M", "Ma", ""], getline(1,3))
195+
%d
196+
197+
" use noselect/noinsert for 'completeopt'
198+
set completeopt&vim
199+
call feedkeys("aM\<f5>\<enter>\<esc>", 'tx')
200+
set completeopt+=noselect
201+
call feedkeys("aM\<f5>\<enter>\<esc>", 'tx')
202+
set completeopt-=noselect completeopt+=noinsert
203+
call feedkeys("aM\<f5>\<enter>\<esc>", 'tx')
204+
call assert_equal(["March", "M", "March"], getline(1,4))
205+
%d
206+
endfu
207+
208+
14209
func! Test_popup_completion_insertmode()
15210
new
16211
inoremap <F5> <C-R>=ListMonths()<CR>
17212
18213
call feedkeys("a\<f5>\<down>\<enter>\<esc>", 'tx')
19214
call assert_equal('February', getline(1))
20215
%d
216+
" Set noinsertmode
21217
let g:setting = 'noinsertmode'
22218
call feedkeys("a\<f5>\<down>\<enter>\<esc>", 'tx')
23219
call assert_equal('February', getline(1))
24220
call assert_false(pumvisible())
25221
%d
222+
" Go through all matches, until none is selected
26223
let g:setting = ''
27224
call feedkeys("a\<f5>". repeat("\<c-n>",12)."\<enter>\<esc>", 'tx')
28225
call assert_equal('', getline(1))
29226
%d
227+
" select previous entry
30228
call feedkeys("a\<f5>\<c-p>\<enter>\<esc>", 'tx')
31229
call assert_equal('', getline(1))
32230
%d
231+
" select last entry
33232
call feedkeys("a\<f5>\<c-p>\<c-p>\<enter>\<esc>", 'tx')
34233
call assert_equal('December', getline(1))
35234

@@ -66,3 +265,5 @@ function! Test() abort
66265
call complete(1, ['source', 'soundfold'])
67266
return ''
68267
endfunction
268+
269+
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

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

764764
static int included_patches[] =
765765
{ /* Add new patch number below this line */
766+
/**/
767+
2146,
766768
/**/
767769
2145,
768770
/**/

0 commit comments

Comments
 (0)