vim-patch:8.1.1138: add CompleteChanged #10644

(This was originally a Neovim patch, but this commit merges some changes
from the Vim patch.)

d7f246c68c
This commit is contained in:
Justin M. Keyes
2019-07-29 02:36:46 +02:00
committed by GitHub
parent 505f47403b
commit caa8c06bae
5 changed files with 79 additions and 31 deletions

View File

@@ -2580,10 +2580,35 @@ static bool pum_enough_matches(void)
return i >= 2;
}
/*
* Show the popup menu for the list of matches.
* Also adjusts "compl_shown_match" to an entry that is actually displayed.
*/
static void trigger_complete_changed_event(int cur)
{
static bool recursive = false;
if (recursive) {
return;
}
dict_T *v_event = get_vim_var_dict(VV_EVENT);
if (cur < 0) {
tv_dict_add_dict(v_event, S_LEN("completed_item"), tv_dict_alloc());
} else {
dict_T *item = ins_compl_dict_alloc(compl_curr_match);
tv_dict_add_dict(v_event, S_LEN("completed_item"), item);
}
pum_set_event_info(v_event);
tv_dict_set_keys_readonly(v_event);
recursive = true;
textlock++;
apply_autocmds(EVENT_COMPLETECHANGED, NULL, NULL, false, curbuf);
textlock--;
recursive = false;
tv_dict_clear(v_event);
}
/// Show the popup menu for the list of matches.
/// Also adjusts "compl_shown_match" to an entry that is actually displayed.
void ins_compl_show_pum(void)
{
compl_T *compl;
@@ -2715,22 +2740,9 @@ void ins_compl_show_pum(void)
pum_display(compl_match_array, compl_match_arraysize, cur, array_changed, 0);
curwin->w_cursor.col = col;
if (!has_event(EVENT_COMPLETECHANGED)) {
return;
if (has_event(EVENT_COMPLETECHANGED)) {
trigger_complete_changed_event(cur);
}
dict_T *dict = get_vim_var_dict(VV_EVENT);
if (cur < 0) {
tv_dict_add_dict(dict, S_LEN("completed_item"), tv_dict_alloc());
} else {
dict_T *item = ins_compl_dict_alloc(compl_curr_match);
tv_dict_add_dict(dict, S_LEN("completed_item"), item);
}
pum_set_boundings(dict);
tv_dict_set_keys_readonly(dict);
textlock++;
apply_autocmds(EVENT_COMPLETECHANGED, NULL, NULL, false, curbuf);
textlock--;
tv_dict_clear(dict);
}
#define DICT_FIRST (1) /* use just first element in "dict" */

View File

@@ -1402,7 +1402,7 @@ int op_delete(oparg_T *oap)
yankreg_T *reg = NULL;
int did_yank = false;
if (oap->regname != 0) {
//yank without message
// yank without message
did_yank = op_yank(oap, false, true);
if (!did_yank) {
// op_yank failed, don't do anything
@@ -3447,7 +3447,7 @@ void ex_display(exarg_T *eap)
MSG_PUTS_ATTR("^J", attr);
n -= 2;
}
for (p = yb->y_array[j]; *p && (n -= ptr2cells(p)) >= 0; p++) { // -V1019
for (p = yb->y_array[j]; *p && (n -= ptr2cells(p)) >= 0; p++) { // -V1019 NOLINT(whitespace/line_length)
clen = (*mb_ptr2len)(p);
msg_outtrans_len(p, clen);
p += clen - 1;

View File

@@ -855,7 +855,8 @@ int pum_get_height(void)
return pum_height;
}
void pum_set_boundings(dict_T *dict)
/// Add size information about the pum to "dict".
void pum_set_event_info(dict_T *dict)
{
if (!pum_visible()) {
return;

View File

@@ -841,4 +841,38 @@ func Test_popup_complete_info_02()
bwipe!
endfunc
func Test_CompleteChanged()
new
call setline(1, ['foo', 'bar', 'foobar', ''])
set complete=. completeopt=noinsert,noselect,menuone
function! OnPumChange()
let g:event = copy(v:event)
let g:item = get(v:event, 'completed_item', {})
let g:word = get(g:item, 'word', v:null)
endfunction
augroup AAAAA_Group
au!
autocmd CompleteChanged * :call OnPumChange()
augroup END
call cursor(4, 1)
call feedkeys("Sf\<C-N>", 'tx')
call assert_equal({'completed_item': {}, 'width': 15,
\ 'height': 2, 'size': 2,
\ 'col': 0, 'row': 4, 'scrollbar': v:false}, g:event)
call feedkeys("a\<C-N>\<C-N>\<C-E>", 'tx')
call assert_equal('foo', g:word)
call feedkeys("a\<C-N>\<C-N>\<C-N>\<C-E>", 'tx')
call assert_equal('foobar', g:word)
call feedkeys("a\<C-N>\<C-N>\<C-N>\<C-N>\<C-E>", 'tx')
call assert_equal(v:null, g:word)
call feedkeys("a\<C-N>\<C-N>\<C-N>\<C-N>\<C-P>", 'tx')
call assert_equal('foobar', g:word)
autocmd! AAAAA_Group
set complete& completeopt&
delfunc! OnPumchange
bw!
endfunc
" vim: shiftwidth=2 sts=2 expandtab