> This looks good to me. Thanks!
Here is a proper patch including a test.
Best,
Christian
--
Der Witz der Theologie besteht darin, daß sie ein höheres Wesen
erfand, um sich selbst ins Leben zu rufen.
-- Martin Kessel
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
From 2220eb03ee22e76ce1e5cc687bdf8e9c8b120c21 Mon Sep 17 00:00:00 2001
From: Christian Brabandt <[email protected]>
Date: Fri, 27 Jan 2017 09:39:49 +0100
Subject: [PATCH] correclty clear completion alternatives on complete()
function
Take this function:
fun! MyComplete()
call complete(1, ['Hello', 'World'])
return ''
endf
And run in a new buffer: ixxx<c-n><c-r>=MyComplete()<cr><c-p>
What happens after keyword completion is, that the list of
candidates is not cleared and when ins_compl_add is called from
set_completion it adds as first item the original text again. So we have
those candidates: xxx->xxx->Hello->World.
It's better to always clear the list of completion candidates when
calling complete() function.
fixes #1411
---
src/edit.c | 1 +
src/testdir/test_popup.vim | 29 +++++++++++++++++++++++++++++
2 files changed, 30 insertions(+)
diff --git a/src/edit.c b/src/edit.c
index 2e1aa2bea..135e02dc5 100644
--- a/src/edit.c
+++ b/src/edit.c
@@ -2821,6 +2821,7 @@ set_completion(colnr_T startcol, list_T *list)
if (ctrl_x_mode != 0)
ins_compl_prep(' ');
ins_compl_clear();
+ ins_compl_free();
compl_direction = FORWARD;
if (startcol > curwin->w_cursor.col)
diff --git a/src/testdir/test_popup.vim b/src/testdir/test_popup.vim
index 96c8d7e30..b5a60b33b 100644
--- a/src/testdir/test_popup.vim
+++ b/src/testdir/test_popup.vim
@@ -482,4 +482,33 @@ func Test_completion_ctrl_e_without_autowrap()
q!
endfunc
+function! DummyCompleteSix()
+ call complete(1, ['Hello', 'World'])
+ return ''
+endfunction
+
+" complete() correctly clears the list of autocomplete candidates
+" See #1411
+func Test_completion_clear_candidate_list()
+ new
+ %d
+ " select first entry from the completion popup
+ call feedkeys("a xxx\<C-N>\<C-R>=DummyCompleteSix()\<CR>", "tx")
+ call assert_equal('Hello', getline(1))
+ %d
+ " select second entry from the completion popup
+ call feedkeys("a xxx\<C-N>\<C-R>=DummyCompleteSix()\<CR>\<C-N>", "tx")
+ call assert_equal('World', getline(1))
+ %d
+ " select original text
+ call feedkeys("a xxx\<C-N>\<C-R>=DummyCompleteSix()\<CR>\<C-N>\<C-N>", "tx")
+ call assert_equal(' xxx', getline(1))
+ %d
+ " back at first entry from completion list
+ call feedkeys("a xxx\<C-N>\<C-R>=DummyCompleteSix()\<CR>\<C-N>\<C-N>\<C-N>", "tx")
+ call assert_equal('Hello', getline(1))
+
+ bw!
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
--
2.11.0