Skip to content

Commit 8e2a229

Browse files
rmuirh-east
authored andcommitted
patch 9.1.1618: completion: incorrect selected index returned from complete_info()
Problem: completion: incorrect selected index returned from complete_info() Solution: Return the index into "items" and restore the previous behaviour (Robert Muir). complete_info() returned an incorrect selected index after 0ac1eb3 (Patch v9.1.1311). Effectively it became an index into "matches" instead of "items". Return the index into "items" by default to restore the previous behavior, unless "matches" was requested. closes: #17952 Co-authored-by: Hirohito Higashi <h.east.727@gmail.com> Signed-off-by: Robert Muir <rmuir@apache.org> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 1434ea0 commit 8e2a229

3 files changed

Lines changed: 28 additions & 5 deletions

File tree

src/insexpand.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4184,8 +4184,8 @@ get_complete_info(list_T *what_list, dict_T *retdict)
41844184
if (compl_curr_match != NULL
41854185
&& compl_curr_match->cp_number == match->cp_number)
41864186
selected_idx = list_idx;
4187-
if (match->cp_in_match_array)
4188-
list_idx += 1;
4187+
if (!has_matches || match->cp_in_match_array)
4188+
list_idx++;
41894189
}
41904190
match = match->cp_next;
41914191
}

src/testdir/test_ins_complete.vim

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3520,7 +3520,7 @@ func Test_complete_opt_fuzzy()
35203520
set cot+=noinsert
35213521
call feedkeys("i\<C-R>=CompAnother()\<CR>f", 'tx')
35223522
call assert_equal("for", g:abbr)
3523-
call assert_equal(0, g:selected)
3523+
call assert_equal(2, g:selected)
35243524

35253525
set cot=menu,menuone,noselect,fuzzy
35263526
call feedkeys("i\<C-R>=CompAnother()\<CR>\<C-N>\<C-N>\<C-N>\<C-N>", 'tx')
@@ -3904,6 +3904,27 @@ func Test_complete_info_completed()
39043904
set cot&
39053905
endfunc
39063906

3907+
func Test_complete_info_selected()
3908+
set completeopt=menuone,noselect
3909+
new
3910+
call setline(1, ["ward", "werd", "wurd", "wxrd"])
3911+
3912+
exe "normal! Gow\<c-n>u\<c-n>\<c-r>=complete_info().selected\<cr>"
3913+
call assert_equal('wurd2', getline(5))
3914+
3915+
exe "normal! Sw\<c-n>u\<c-n>\<c-r>=complete_info(['selected']).selected\<cr>"
3916+
call assert_equal('wurd2', getline(5))
3917+
3918+
exe "normal! Sw\<c-n>u\<c-n>\<c-r>=complete_info(['items', 'selected']).selected\<cr>"
3919+
call assert_equal('wurd2', getline(5))
3920+
3921+
exe "normal! Sw\<c-n>u\<c-n>\<c-r>=complete_info(['matches', 'selected']).selected\<cr>"
3922+
call assert_equal('wurd0', getline(5))
3923+
3924+
bw!
3925+
set cot&
3926+
endfunc
3927+
39073928
func Test_completeopt_preinsert()
39083929
func Omni_test(findstart, base)
39093930
if a:findstart
@@ -3924,7 +3945,7 @@ func Test_completeopt_preinsert()
39243945
call assert_equal("fobar", g:line)
39253946
call assert_equal(2, g:col)
39263947

3927-
call feedkeys("S\<C-X>\<C-O>foo\<F5><ESC>", 'tx')
3948+
call feedkeys("S\<C-X>\<C-O>foo\<F5>\<ESC>", 'tx')
39283949
call assert_equal("foobar", g:line)
39293950

39303951
call feedkeys("S\<C-X>\<C-O>foo\<BS>\<BS>\<BS>", 'tx')
@@ -5067,7 +5088,7 @@ func Test_autocomplete_trigger()
50675088

50685089
new
50695090
inoremap <buffer> <F2> <Cmd>let b:matches = complete_info(["matches"]).matches<CR>
5070-
inoremap <buffer> <F3> <Cmd>let b:selected = complete_info(["selected"]).selected<CR>
5091+
inoremap <buffer> <F3> <Cmd>let b:selected = complete_info(["matches", "selected"]).selected<CR>
50715092
50725093
call setline(1, ['abc', 'abcd', 'fo', 'b', ''])
50735094
set autocomplete

src/version.c

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

720720
static int included_patches[] =
721721
{ /* Add new patch number below this line */
722+
/**/
723+
1618,
722724
/**/
723725
1617,
724726
/**/

0 commit comments

Comments
 (0)