From 447bfba24b231777a79bf53cdb33f44d9691e47e Mon Sep 17 00:00:00 2001
From: Bram Moolenaar <Bram@vim.org>
Date: Sat, 18 Jul 2020 16:07:16 +0200
Subject: [PATCH] patch 8.2.1237: changing 'completepopup' after opening popup
 has no effect

Problem:    Changing 'completepopup' after opening a popup has no effect. (Jay
            Sitter)
Solution:   Close the popup when the options are changed. (closes #6471)
---
 runtime/doc/options.txt                          |  8 +++++---
 src/optionstr.c                                  |  2 ++
 src/popupwin.c                                   | 12 ++++++++++++
 src/proto/popupwin.pro                           |  1 +
 src/testdir/dumps/Test_popupwin_infopopup_8.dump | 14 ++++++++++++++
 src/testdir/test_popupwin.vim                    |  6 ++++++
 src/version.c                                    |  2 ++
 7 files changed, 42 insertions(+), 3 deletions(-)
 create mode 100644 src/testdir/dumps/Test_popupwin_infopopup_8.dump

diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index 37fdc84bcd..71ee94b4e5 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -1951,9 +1951,11 @@ A jump table for the options with a short description can be found at |Q_op|.
 			{not available when compiled without the |+textprop|
 			or |+quickfix| feature}
 	When 'completeopt' contains "popup" then this option is used for the
-	properties of the info popup when it is created.  You can also use
-	|popup_findinfo()| and then set properties for an existing info popup
-	with |popup_setoptions()|.  See |complete-popup|.
+	properties of the info popup when it is created.  If an info popup
+	window already exists it is closed, so that the option value is
+	applied when it is created again.
+	You can also use |popup_findinfo()| and then set properties for an
+	existing info popup with |popup_setoptions()|.  See |complete-popup|.
 
 
 						*'concealcursor'* *'cocu'*
diff --git a/src/optionstr.c b/src/optionstr.c
index a0409fa771..bfc2e3b955 100644
--- a/src/optionstr.c
+++ b/src/optionstr.c
@@ -2249,6 +2249,8 @@ did_set_string_option(
     {
 	if (parse_completepopup(NULL) == FAIL)
 	    errmsg = e_invarg;
+	else
+	    popup_close_info();
     }
 # endif
 #endif
diff --git a/src/popupwin.c b/src/popupwin.c
index 296441b11b..b0b4737c77 100644
--- a/src/popupwin.c
+++ b/src/popupwin.c
@@ -4031,6 +4031,18 @@ popup_hide_info(void)
     if (wp != NULL)
 	popup_hide(wp);
 }
+
+/*
+ * Close any info popup.
+ */
+    void
+popup_close_info(void)
+{
+    win_T *wp = popup_find_info_window();
+
+    if (wp != NULL)
+	popup_close_with_retval(wp, -1);
+}
 #endif
 
 /*
diff --git a/src/proto/popupwin.pro b/src/proto/popupwin.pro
index 02cdce33ab..fe75702cef 100644
--- a/src/proto/popupwin.pro
+++ b/src/proto/popupwin.pro
@@ -60,6 +60,7 @@ void f_popup_findpreview(typval_T *argvars, typval_T *rettv);
 int popup_create_preview_window(int info);
 void popup_close_preview(void);
 void popup_hide_info(void);
+void popup_close_info(void);
 int popup_win_closed(win_T *win);
 void popup_set_title(win_T *wp);
 void popup_update_preview_title(void);
diff --git a/src/testdir/dumps/Test_popupwin_infopopup_8.dump b/src/testdir/dumps/Test_popupwin_infopopup_8.dump
new file mode 100644
index 0000000000..6838bcd8b5
--- /dev/null
+++ b/src/testdir/dumps/Test_popupwin_infopopup_8.dump
@@ -0,0 +1,14 @@
+|a+0&#ffffff0|w|o|r|d| @69
+|t|e|s|t| |t|a|w|o|r|d> @63
+|~+0#4040ff13&| @3| +0#0000001#e0e0e08|w|r|d| @4|W| |e|x|t|r|a| |t|e|x|t| @1| +0#0000000#0000001| +0#0000001#e0e0e08|w|o|r|d|s| |a|r|e| |c|o@1|l| | +0#4040ff13#ffffff0@29
+|~| @3| +0#0000001#ffd7ff255|a|n|o|t|w|r|d| |W| |e|x|t|r|a| |t|e|x|t| @1| +0#0000000#0000001| +0#4040ff13#ffffff0@45
+|~| @3| +0#0000001#ffd7ff255|n|o|a|w|r|d| @1|W| |e|x|t|r|a| |t|e|x|t| @1| +0#0000000#a8a8a8255| +0#4040ff13#ffffff0@45
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|-+2#0000000&@1| |U|s|e|r| |d|e|f|i|n|e|d| |c|o|m|p|l|e|t|i|o|n| |(|^|U|^|N|^|P|)| |m+0#00e0003&|a|t|c|h| |1| |o|f| |4| +0#0000000&@26
diff --git a/src/testdir/test_popupwin.vim b/src/testdir/test_popupwin.vim
index 8df01e15a6..054d479efd 100644
--- a/src/testdir/test_popupwin.vim
+++ b/src/testdir/test_popupwin.vim
@@ -3109,6 +3109,12 @@ func Test_popupmenu_info_border()
   call term_sendkeys(buf, "otest text test text\<C-X>\<C-U>")
   call VerifyScreenDump(buf, 'Test_popupwin_infopopup_7', {})
 
+  " Test that when the option is changed the popup changes.
+  call term_sendkeys(buf, "\<Esc>")
+  call term_sendkeys(buf, ":set completepopup=border:off\<CR>")
+  call term_sendkeys(buf, "a\<C-X>\<C-U>")
+  call VerifyScreenDump(buf, 'Test_popupwin_infopopup_8', {})
+
   call term_sendkeys(buf, "\<Esc>")
   call StopVimInTerminal(buf)
   call delete('XtestInfoPopup')
diff --git a/src/version.c b/src/version.c
index d8353cc4a7..06f7fd2b85 100644
--- a/src/version.c
+++ b/src/version.c
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1237,
 /**/
     1236,
 /**/
-- 
GitLab