aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/doc/autocmd.txt19
-rw-r--r--src/nvim/edit.c50
-rw-r--r--src/nvim/ops.c4
-rw-r--r--src/nvim/popupmnu.c3
-rw-r--r--src/nvim/testdir/test_popup.vim34
5 files changed, 79 insertions, 31 deletions
diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt
index 461167015d..a3f13034a8 100644
--- a/runtime/doc/autocmd.txt
+++ b/runtime/doc/autocmd.txt
@@ -590,18 +590,19 @@ CompleteDone After Insert mode completion is done. Either
completed item.
CompleteChanged *CompleteChanged*
- After each time popup menu changed, not fired
- on popup menu hide, use |CompleteDone| for popup
- menu hide.
+ After each time the Insert mode completion
+ menu changed. Not fired on popup menu hide,
+ use |CompleteDone| for that. Never triggered
+ recursively.
Sets these |v:event| keys:
completed_item
- height
- width
- row
- col
- size
- scrollbar
+ height nr of items visible
+ width screen cells
+ row top screen row
+ col leftmost screen column
+ size total nr of items
+ scrollbar TRUE if visible
It is not allowed to change the text |textlock|.
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