Here is a slightly updated patch, that allows to
exit insert mode only, when the popupmenu is not
visible.

Best,
Christian
-- 
Ich liebe es, wenn im Winter Schnee liegt. Dann sieht mein Rasen so schön
aus, wie der von meinen Nachbarn.

-- 
-- 
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 a10e65c24d3f3305c72fd6bca4f04ad31e5a0081 Mon Sep 17 00:00:00 2001
From: Christian Brabandt <[email protected]>
Date: Thu, 23 Jun 2016 17:18:51 +0200
Subject: [PATCH] When resetting 'im' only stop insertmode, if it was set
 previously

This fixes a bug, that resetting 'im' while the completion menu
was open would leave the popupmenu visible while stopping insert mode.

Simple example:
inoremap <F5> <C-R>=ListMonths()<CR>

func! ListMonths()
  set noinsertmode
  call complete(col('.'), ['January', 'February', 'March',
	\ 'April', 'May', 'June', 'July', 'August', 'September',
	\ 'October', 'November', 'December'])
  return ''
endfunc

Add a test, that this works.
---
 src/edit.c                 |  6 +++++-
 src/option.c               |  3 ++-
 src/testdir/test_alot.vim  |  1 +
 src/testdir/test_popup.vim | 38 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 46 insertions(+), 2 deletions(-)
 create mode 100644 src/testdir/test_popup.vim

diff --git a/src/edit.c b/src/edit.c
index 0ba2627..234e03d 100644
--- a/src/edit.c
+++ b/src/edit.c
@@ -649,7 +649,11 @@ edit(
 	if (update_Insstart_orig)
 	    Insstart_orig = Insstart;
 
-	if (stop_insert_mode)
+	if (stop_insert_mode
+#ifdef FEAT_INS_EXPAND
+		&& !pum_visible()
+#endif
+		)
 	{
 	    /* ":stopinsert" used or 'insertmode' reset */
 	    count = 0;
diff --git a/src/option.c b/src/option.c
index b17fc28..2829900 100644
--- a/src/option.c
+++ b/src/option.c
@@ -8001,7 +8001,8 @@ set_bool_option(
 		need_start_insertmode = TRUE;
 	    stop_insert_mode = FALSE;
 	}
-	else
+	/* only reset, if it was set previously */
+	else if (old_value)
 	{
 	    need_start_insertmode = FALSE;
 	    stop_insert_mode = TRUE;
diff --git a/src/testdir/test_alot.vim b/src/testdir/test_alot.vim
index d8d460a..444085e 100644
--- a/src/testdir/test_alot.vim
+++ b/src/testdir/test_alot.vim
@@ -21,6 +21,7 @@ source test_matchstrpos.vim
 source test_menu.vim
 source test_messages.vim
 source test_partial.vim
+source test_popup.vim
 source test_reltime.vim
 source test_searchpos.vim
 source test_set.vim
diff --git a/src/testdir/test_popup.vim b/src/testdir/test_popup.vim
new file mode 100644
index 0000000..dcdd52c
--- /dev/null
+++ b/src/testdir/test_popup.vim
@@ -0,0 +1,38 @@
+" Test for completion menu
+
+inoremap <F5> <C-R>=ListMonths()<CR>
+let g:months=['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
+let g:setting=''
+
+func! Set(val)
+    if a:val
+	exe ":set" a:val
+    endif
+endfunc
+func! ListMonths()
+    call Set(g:setting)
+    call complete(col('.'), g:months) 
+    return ''
+endfunc
+
+func! Test_popup_completion_insertmode()
+    new
+    call feedkeys("a\<f5>\<down>\<enter>\<esc>", 'tx')
+    call assert_equal('February', getline(1))
+    %d
+    let g:setting='noinsertmode'
+    call feedkeys("a\<f5>\<down>\<enter>\<esc>", 'tx')
+    call assert_equal('February', getline(1))
+    call assert_false(pumvisible())
+    %d
+    let g:setting=''
+    call feedkeys("a\<f5>". repeat("\<c-n>",12)."\<enter>\<esc>", 'tx')
+    call assert_equal('', getline(1))
+    %d
+    call feedkeys("a\<f5>\<c-p>\<enter>\<esc>", 'tx')
+    call assert_equal('', getline(1))
+    %d
+    call feedkeys("a\<f5>\<c-p>\<c-p>\<enter>\<esc>", 'tx')
+    call assert_equal('December', getline(1))
+    %d
+endfunc
-- 
2.1.4

Raspunde prin e-mail lui