vim-patch:9.1.0489: default completion may break with fuzzy (#29364)

Problem:  default completion may break with fuzzy
Solution: check that completion_match_array is not null
          (glepnir)

closes: vim/vim#15010

aced8c2f4f

Co-authored-by: glepnir <glephunter@gmail.com>
This commit is contained in:
zeertzjq
2024-06-16 07:07:06 +08:00
committed by GitHub
parent 7e65f3757b
commit aa319da402
2 changed files with 14 additions and 4 deletions

View File

@@ -3698,16 +3698,16 @@ static int find_next_completion_match(bool allow_get_expansion, int todo, bool a
while (--todo >= 0) { while (--todo >= 0) {
if (compl_shows_dir_forward() && compl_shown_match->cp_next != NULL) { if (compl_shows_dir_forward() && compl_shown_match->cp_next != NULL) {
compl_shown_match = !compl_fuzzy_match ? compl_shown_match->cp_next compl_shown_match = compl_fuzzy_match && compl_match_array != NULL
: find_comp_when_fuzzy(); ? find_comp_when_fuzzy() : compl_shown_match->cp_next;
found_end = (compl_first_match != NULL found_end = (compl_first_match != NULL
&& (is_first_match(compl_shown_match->cp_next) && (is_first_match(compl_shown_match->cp_next)
|| is_first_match(compl_shown_match))); || is_first_match(compl_shown_match)));
} else if (compl_shows_dir_backward() } else if (compl_shows_dir_backward()
&& compl_shown_match->cp_prev != NULL) { && compl_shown_match->cp_prev != NULL) {
found_end = is_first_match(compl_shown_match); found_end = is_first_match(compl_shown_match);
compl_shown_match = !compl_fuzzy_match ? compl_shown_match->cp_prev compl_shown_match = compl_fuzzy_match && compl_match_array != NULL
: find_comp_when_fuzzy(); ? find_comp_when_fuzzy() : compl_shown_match->cp_prev;
found_end |= is_first_match(compl_shown_match); found_end |= is_first_match(compl_shown_match);
} else { } else {
if (!allow_get_expansion) { if (!allow_get_expansion) {

View File

@@ -2634,6 +2634,16 @@ func Test_complete_fuzzy_match()
call feedkeys("S\<C-x>\<C-o>fb\<C-n>", 'tx') call feedkeys("S\<C-x>\<C-o>fb\<C-n>", 'tx')
call assert_equal('fooBaz', g:word) call assert_equal('fooBaz', g:word)
" avoid break default completion behavior
set completeopt=fuzzy,menu
call setline(1, ['hello help hero h'])
exe "norm! A\<C-X>\<C-N>"
call assert_equal('hello help hero hello', getline('.'))
set completeopt+=noinsert
call setline(1, ['hello help hero h'])
exe "norm! A\<C-X>\<C-N>"
call assert_equal('hello help hero h', getline('.'))
" clean up " clean up
set omnifunc= set omnifunc=
bw! bw!