patch 8.1.1609: the user cannot easily close a popup window
Problem: The user cannot easily close a popup window.
Solution: Add the "close" property. (mostly by Masato Nishihata,
closes #4601)
diff --git a/src/testdir/dumps/Test_popupwin_close_01.dump b/src/testdir/dumps/Test_popupwin_close_01.dump
new file mode 100644
index 0000000..e11ae83
--- /dev/null
+++ b/src/testdir/dumps/Test_popupwin_close_01.dump
@@ -0,0 +1,10 @@
+>╔+0#0000001#ffd7ff255|═@5|X| +0#0000000#ffffff0@66
+|║+0#0000001#ffd7ff255|f|o@1|b|a|r|║| +0#0000000#ffffff0@66
+|╚+0#0000001#ffd7ff255|═@5|╝| +0#0000000#ffffff0@5|n+0#0000001#ffd7ff255|o|t|i|f|i|c|a|t|i|o|n| +0#0000000#ffffff0@48
+|4| @73
+|5| |n+0#0000001#ffd7ff255|o| |b|o|r|d|e|r| |h|e|r|X| +0#0000000#ffffff0@5| +0#0000001#ffd7ff255@12|X| +0#0000000#ffffff0@38
+|6| @20| +0#0000001#ffd7ff255|o|n|l|y| |p|a|d@1|i|n|g| | +0#0000000#ffffff0@38
+|7| @20| +0#0000001#ffd7ff255@13| +0#0000000#ffffff0@38
+|8| @73
+|9| @73
+@57|1|,|1| @10|T|o|p|
diff --git a/src/testdir/dumps/Test_popupwin_close_02.dump b/src/testdir/dumps/Test_popupwin_close_02.dump
new file mode 100644
index 0000000..75342ef
--- /dev/null
+++ b/src/testdir/dumps/Test_popupwin_close_02.dump
@@ -0,0 +1,10 @@
+>1+0&#ffffff0| @73
+|2| @73
+|3| @12|n+0#0000001#ffd7ff255|o|t|i|f|i|c|a|t|i|o|n| +0#0000000#ffffff0@48
+|4| @73
+|5| |n+0#0000001#ffd7ff255|o| |b|o|r|d|e|r| |h|e|r|X| +0#0000000#ffffff0@5| +0#0000001#ffd7ff255@12|X| +0#0000000#ffffff0@38
+|6| @20| +0#0000001#ffd7ff255|o|n|l|y| |p|a|d@1|i|n|g| | +0#0000000#ffffff0@38
+|7| @20| +0#0000001#ffd7ff255@13| +0#0000000#ffffff0@38
+|8| @73
+|9| @73
+|:|c|a|l@1| |C|l|o|s|e|W|i|t|h|X|(|)| @38|1|,|1| @10|T|o|p|
diff --git a/src/testdir/dumps/Test_popupwin_close_03.dump b/src/testdir/dumps/Test_popupwin_close_03.dump
new file mode 100644
index 0000000..82438c8
--- /dev/null
+++ b/src/testdir/dumps/Test_popupwin_close_03.dump
@@ -0,0 +1,10 @@
+>1+0&#ffffff0| @73
+|2| @73
+|3| @73
+|4| @73
+|5| |n+0#0000001#ffd7ff255|o| |b|o|r|d|e|r| |h|e|r|X| +0#0000000#ffffff0@5| +0#0000001#ffd7ff255@12|X| +0#0000000#ffffff0@38
+|6| @20| +0#0000001#ffd7ff255|o|n|l|y| |p|a|d@1|i|n|g| | +0#0000000#ffffff0@38
+|7| @20| +0#0000001#ffd7ff255@13| +0#0000000#ffffff0@38
+|8| @73
+|9| @73
+|P|o|p|u|p| |c|l|o|s|e|d| |w|i|t|h| |-|2| @36|1|,|1| @10|T|o|p|
diff --git a/src/testdir/test_popupwin.vim b/src/testdir/test_popupwin.vim
index f4bc33c..a3e6acc 100644
--- a/src/testdir/test_popupwin.vim
+++ b/src/testdir/test_popupwin.vim
@@ -365,6 +365,63 @@
call delete('XtestPopupDrag')
endfunc
+func Test_popup_close_with_mouse()
+ if !CanRunVimInTerminal()
+ throw 'Skipped: cannot make screendumps'
+ endif
+ let lines =<< trim END
+ call setline(1, range(1, 20))
+ " With border, can click on X
+ let winid = popup_create('foobar', {
+ \ 'close': 'button',
+ \ 'border': [],
+ \ 'line': 1,
+ \ 'col': 1,
+ \ })
+ func CloseMsg(id, result)
+ echomsg 'Popup closed with ' .. a:result
+ endfunc
+ let winid = popup_create('notification', {
+ \ 'close': 'click',
+ \ 'line': 3,
+ \ 'col': 15,
+ \ 'callback': 'CloseMsg',
+ \ })
+ let winid = popup_create('no border here', {
+ \ 'close': 'button',
+ \ 'line': 5,
+ \ 'col': 3,
+ \ })
+ let winid = popup_create('only padding', {
+ \ 'close': 'button',
+ \ 'padding': [],
+ \ 'line': 5,
+ \ 'col': 23,
+ \ })
+ func CloseWithX()
+ call feedkeys("\<F3>\<LeftMouse>\<LeftRelease>", "xt")
+ endfunc
+ map <silent> <F3> :call test_setmouse(1, len('foobar') + 2)<CR>
+ func CloseWithClick()
+ call feedkeys("\<F4>\<LeftMouse>\<LeftRelease>", "xt")
+ endfunc
+ map <silent> <F4> :call test_setmouse(3, 17)<CR>
+ END
+ call writefile(lines, 'XtestPopupClose')
+ let buf = RunVimInTerminal('-S XtestPopupClose', {'rows': 10})
+ call VerifyScreenDump(buf, 'Test_popupwin_close_01', {})
+
+ call term_sendkeys(buf, ":call CloseWithX()\<CR>")
+ call VerifyScreenDump(buf, 'Test_popupwin_close_02', {})
+
+ call term_sendkeys(buf, ":call CloseWithClick()\<CR>")
+ call VerifyScreenDump(buf, 'Test_popupwin_close_03', {})
+
+ " clean up
+ call StopVimInTerminal(buf)
+ call delete('XtestPopupClose')
+endfunction
+
func Test_popup_with_mask()
if !CanRunVimInTerminal()
throw 'Skipped: cannot make screendumps'