diff --git a/src/insexpand.c b/src/insexpand.c index 3a775422d7..991c9d23d0 100644 --- a/src/insexpand.c +++ b/src/insexpand.c @@ -4184,8 +4184,8 @@ get_complete_info(list_T *what_list, dict_T *retdict) if (compl_curr_match != NULL && compl_curr_match->cp_number == match->cp_number) selected_idx = list_idx; - if (match->cp_in_match_array) - list_idx += 1; + if (!has_matches || match->cp_in_match_array) + list_idx++; } match = match->cp_next; } diff --git a/src/testdir/test_ins_complete.vim b/src/testdir/test_ins_complete.vim index 1ec71118c9..6964a537e9 100644 --- a/src/testdir/test_ins_complete.vim +++ b/src/testdir/test_ins_complete.vim @@ -3520,7 +3520,7 @@ func Test_complete_opt_fuzzy() set cot+=noinsert call feedkeys("i\=CompAnother()\f", 'tx') call assert_equal("for", g:abbr) - call assert_equal(0, g:selected) + call assert_equal(2, g:selected) set cot=menu,menuone,noselect,fuzzy call feedkeys("i\=CompAnother()\\\\\", 'tx') @@ -3904,6 +3904,27 @@ func Test_complete_info_completed() set cot& endfunc +func Test_complete_info_selected() + set completeopt=menuone,noselect + new + call setline(1, ["ward", "werd", "wurd", "wxrd"]) + + exe "normal! Gow\u\\=complete_info().selected\" + call assert_equal('wurd2', getline(5)) + + exe "normal! Sw\u\\=complete_info(['selected']).selected\" + call assert_equal('wurd2', getline(5)) + + exe "normal! Sw\u\\=complete_info(['items', 'selected']).selected\" + call assert_equal('wurd2', getline(5)) + + exe "normal! Sw\u\\=complete_info(['matches', 'selected']).selected\" + call assert_equal('wurd0', getline(5)) + + bw! + set cot& +endfunc + func Test_completeopt_preinsert() func Omni_test(findstart, base) if a:findstart @@ -3924,7 +3945,7 @@ func Test_completeopt_preinsert() call assert_equal("fobar", g:line) call assert_equal(2, g:col) - call feedkeys("S\\foo\", 'tx') + call feedkeys("S\\foo\\", 'tx') call assert_equal("foobar", g:line) call feedkeys("S\\foo\\\", 'tx') @@ -5067,7 +5088,7 @@ func Test_autocomplete_trigger() new inoremap let b:matches = complete_info(["matches"]).matches - inoremap let b:selected = complete_info(["selected"]).selected + inoremap let b:selected = complete_info(["matches", "selected"]).selected call setline(1, ['abc', 'abcd', 'fo', 'b', '']) set autocomplete diff --git a/src/version.c b/src/version.c index ca657305d2..e61d4fc81a 100644 --- a/src/version.c +++ b/src/version.c @@ -719,6 +719,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1618, /**/ 1617, /**/