On Do, 23 Jun 2016, Christian Brabandt wrote:

> Am 2016-06-23 00:28, schrieb Christian Brabandt:
> >Bram,
> >I have a plugin (unicode.vim https://github.com/chrisbra/unicode.vim),
> >that allows to complete digraphs characters from insert mode using
> >i_CTRL-R_= and the complete() function.
> >
> >I got an issue with the very first call of the completion function
> >(https://github.com/chrisbra/unicode.vim/issues/16#issuecomment-226560333)
> >
> >On the very first call, when the unicode database is not available, the
> >plugin tries to download it using netrw. It basically calls :Nread
> >http://www.unicode.org/Public/UNIDATA/UnicodeData.txt
> >
> >After this is done, it parses the unicode database and presents a nice
> >popup menu. In the process of downloading the data, netrw resets some
> >options, among which is 'insertmode' That has the effect, that
> >stop_insert_mode() will be set to TRUE and upon returning from the
> >insert mode completion (i_CTRL-R_=) mapping, will end insert mode and
> >therefore, Vim is effectively in Normal mode, while the popup menu is
> >still drawn.
> >
> >This has the funny effect, that for the user there does not seem
> >to be a
> >possibility to close the popupmenu anymore and it stays open, which is
> >very irritating.
> >
> >This happens, although netrw is restoring the value after finishing
> >downloading, but stop_insert_mode is never reset to the old FALSE
> >value.
> [...]
> 
> Here is a simple example, taken from :h complete() and slightly
> adjusted:
> 
> 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
> 
> Note, after pressing <f5> in insert mode you are back in normal mode,
> can navigate normally but the popupmenu is still active (and won't
> disappear after e.g. :redraw!). Also :echo pumvisible() returns 1.
> 
> I'll try to add a testcase for that. Note, that noinsertmode should
> be a no-op, as it is off by default.

I think this patch is better. Also it adds a some simple testcase for 
insertmode completion.

Mit freundlichen Grüßen
Christian
-- 
Der Mensch muss bei dem Glauben verharren, dass das 
Unbegreifliche begreiflich sei; er würde sonst nicht forschen.
                -- Goethe, Maximen und Reflektionen, Nr. 880

-- 
-- 
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 0f39fa2832d0b4968adc45b78e0a9adfd27b7f28 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/option.c               |  3 ++-
 src/testdir/test_alot.vim  |  1 +
 src/testdir/test_popup.vim | 38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 41 insertions(+), 1 deletion(-)
 create mode 100644 src/testdir/test_popup.vim

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