diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2019-07-29 02:36:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-29 02:36:46 +0200 |
commit | caa8c06bae0ff351edb22d566a92a4b1009f191d (patch) | |
tree | 69052a0f25d5b6e9207dacbec2da568866cac92d /src | |
parent | 505f47403ba6a95179ae854c80db07ae77d70947 (diff) | |
download | rneovim-caa8c06bae0ff351edb22d566a92a4b1009f191d.tar.gz rneovim-caa8c06bae0ff351edb22d566a92a4b1009f191d.tar.bz2 rneovim-caa8c06bae0ff351edb22d566a92a4b1009f191d.zip |
vim-patch:8.1.1138: add CompleteChanged #10644
(This was originally a Neovim patch, but this commit merges some changes
from the Vim patch.)
https://github.com/vim/vim/commit/d7f246c68cfb97406bcd4b098a2df2d870b3ef92
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/edit.c | 50 | ||||
-rw-r--r-- | src/nvim/ops.c | 4 | ||||
-rw-r--r-- | src/nvim/popupmnu.c | 3 | ||||
-rw-r--r-- | src/nvim/testdir/test_popup.vim | 34 |
4 files changed, 69 insertions, 22 deletions
diff --git a/src/nvim/edit.c b/src/nvim/edit.c index a3487e012a..06f8cc9413 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -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" */ diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 28635a4383..6709e52679 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -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; diff --git a/src/nvim/popupmnu.c b/src/nvim/popupmnu.c index ef4330003f..ce40bc15e0 100644 --- a/src/nvim/popupmnu.c +++ b/src/nvim/popupmnu.c @@ -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; diff --git a/src/nvim/testdir/test_popup.vim b/src/nvim/testdir/test_popup.vim index 557f60751c..98e9de9ffb 100644 --- a/src/nvim/testdir/test_popup.vim +++ b/src/nvim/testdir/test_popup.vim @@ -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 |