changeset 17879:5d5b460926ca v8.1.1936

patch 8.1.1936: not enough tests for text property popup window Commit: https://github.com/vim/vim/commit/1fb0831a0e9f9b6f18f1f8b549191bd547d0e095 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Aug 29 20:02:11 2019 +0200 patch 8.1.1936: not enough tests for text property popup window Problem: Not enough tests for text property popup window. Solution: Add a few more tests. Make negative offset work. Close all popups when window closes.
author Bram Moolenaar <Bram@vim.org>
date Thu, 29 Aug 2019 20:15:04 +0200
parents 74fec19ccefb
children 80cfe34033fc
files src/popupwin.c src/testdir/dumps/Test_popup_textprop_07.dump src/testdir/dumps/Test_popup_textprop_corn_5.dump src/testdir/dumps/Test_popup_textprop_corn_6.dump src/testdir/dumps/Test_popup_textprop_off_1.dump src/testdir/dumps/Test_popup_textprop_off_2.dump src/testdir/test_popupwin_textprop.vim src/version.c
diffstat 8 files changed, 147 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/popupwin.c
+++ b/src/popupwin.c
@@ -33,6 +33,7 @@ static void popup_adjust_position(win_T 
 /*
  * Get option value for "key", which is "line" or "col".
  * Handles "cursor+N" and "cursor-N".
+ * Returns MAXCOL if the entry is not present.
  */
     static int
 popup_options_one(dict_T *dict, char_u *key)
@@ -45,7 +46,7 @@ popup_options_one(dict_T *dict, char_u *
 
     di = dict_find(dict, key, -1);
     if (di == NULL)
-	return 0;
+	return MAXCOL;
 
     val = tv_get_string(&di->di_tv);
     if (STRNCMP(val, "cursor", 6) != 0)
@@ -408,10 +409,10 @@ apply_move_options(win_T *wp, dict_T *d)
 	wp->w_maxheight = nr;
 
     nr = popup_options_one(d, (char_u *)"line");
-    if (nr > 0)
+    if (nr != MAXCOL)
 	wp->w_wantline = nr;
     nr = popup_options_one(d, (char_u *)"col");
-    if (nr > 0)
+    if (nr != MAXCOL)
 	wp->w_wantcol = nr;
 
     di = dict_find(d, (char_u *)"fixed", -1);
@@ -1114,7 +1115,7 @@ popup_adjust_position(win_T *wp)
     }
     else
     {
-	if (wantline != 0 && (wp->w_popup_pos == POPPOS_TOPLEFT
+	if (wantline > 0 && (wp->w_popup_pos == POPPOS_TOPLEFT
 		|| wp->w_popup_pos == POPPOS_TOPRIGHT))
 	{
 	    wp->w_winrow = wantline - 1;
@@ -1124,8 +1125,8 @@ popup_adjust_position(win_T *wp)
 
 	if (wantcol == 0)
 	    center_hor = TRUE;
-	else if (wp->w_popup_pos == POPPOS_TOPLEFT
-		|| wp->w_popup_pos == POPPOS_BOTLEFT)
+	else if (wantcol > 0 && (wp->w_popup_pos == POPPOS_TOPLEFT
+		|| wp->w_popup_pos == POPPOS_BOTLEFT))
 	{
 	    wp->w_wincol = wantcol - 1;
 	    if (wp->w_wincol >= Columns - 3)
@@ -3587,21 +3588,23 @@ popup_hide_info(void)
     int
 popup_win_closed(win_T *win)
 {
-    win_T *wp;
-
-    for (wp = first_popupwin; wp != NULL; wp = wp->w_next)
-	if (wp->w_popup_prop_win == win)
+    int	    round;
+    win_T   *wp;
+    win_T   *next;
+    int	    ret = FALSE;
+
+    for (round = 1; round <= 2; ++round)
+	for (wp = round == 1 ? first_popupwin : curtab->tp_first_popupwin;
+							 wp != NULL; wp = next)
 	{
-	    popup_close_with_retval(wp, -1);
-	    return TRUE;
+	    next = wp->w_next;
+	    if (wp->w_popup_prop_win == win)
+	    {
+		popup_close_with_retval(wp, -1);
+		ret = TRUE;
+	    }
 	}
-    for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next)
-	if (wp->w_popup_prop_win == win)
-	{
-	    popup_close_with_retval(wp, -1);
-	    return TRUE;
-	}
-    return FALSE;
+    return ret;
 }
 
 /*
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_popup_textprop_07.dump
@@ -0,0 +1,10 @@
+>5+0&#ffffff0|1| @72
+|5|2| @72
+|5|3| @72
+|5|4| @72
+|5@1| @72
+|5|6| @72
+|5|7| @72
+|5|8| @72
+|5|9| @72
+@57|5|0|,|1| @9|5|4|%| 
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_popup_textprop_corn_5.dump
@@ -0,0 +1,12 @@
+> +0&#ffffff0@36||+1&&|4+0&&|5| @34
+|~+0#4040ff13&| @35||+1#0000000&|4+0&&|6| @34
+|~+0#4040ff13&| @35||+1#0000000&|4+0&&|7|╔+0#0000001#ffd7ff255|═@13|╗| +0#0000000#ffffff0@18
+|~+0#4040ff13&| @35||+1#0000000&|4+0&&|8|║+0#0000001#ffd7ff255| |b|o|t@1|o|m| |r|i|g|h|t| |║| +0#0000000#ffffff0@18
+|~+0#4040ff13&| @35||+1#0000000&|4+0&&|9|╚+0#0000001#ffd7ff255|═@13|╝| +0#0000000#ffffff0@5| +0#0000001#ffd7ff255|b|o|t@1|o|m| |l|e|f|t| 
+|~+0#4040ff13#ffffff0| @35||+1#0000000&|w+0&&|o|r|k|i|n|g| |w|i|t|h| |s|o|m|e| |l+0&#5fd7ff255|o|n|g|e|r| +0&#ffffff0|t|e|x|t| |h|e|r|e| @2
+|~+0#4040ff13&| @35||+1#0000000&|5+0&&|1| @4| +0#0000001#ffd7ff255|t|o|p| |r|i|g|h|t| | +0#0000000#ffffff0@5|╔+0#0000001#ffd7ff255|═@9|╗| +0#0000000#ffffff0
+|~+0#4040ff13&| @35||+1#0000000&|5+0&&|2| @21|║+0#0000001#ffd7ff255| |t|o|p| |l|e|f|t| |║| +0#0000000#ffffff0
+|~+0#4040ff13&| @35||+1#0000000&|5+0&&|3| @21|╚+0#0000001#ffd7ff255|═@9|╝| +0#0000000#ffffff0
+|~+0#4040ff13&| @35||+1#0000000&|5+0&&|4| @34
+|f+3&&|o@1| @15|0|,|0|-|1| @9|A|l@1| |[+1&&|N|o| |N|a|m|e|]| |[|+|]| @5|4|6|,|1| @10|4|8|%
+|"+0&&|f|o@1|"| |[|N|e|w| |F|i|l|e|]| @58
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_popup_textprop_corn_6.dump
@@ -0,0 +1,12 @@
+> +0&#ffffff0@74
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|:+0#0000000&|o|n|l|y|!| @50|0|,|0|-|1| @8|A|l@1| 
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_popup_textprop_off_1.dump
@@ -0,0 +1,12 @@
+|4+0&#ffffff0|5| @72
+|4|6| @1|╔+0#0000001#ffd7ff255|═@13|╗| +0#0000000#ffffff0@54
+|4|7| @1|║+0#0000001#ffd7ff255| |b|o|t@1|o|m| |r|i|g|h|t| |║| +0#0000000#ffffff0@54
+|4|8| @1|╚+0#0000001#ffd7ff255|═@13|╝| +0#0000000#ffffff0@9| +0#0000001#ffd7ff255|b|o|t@1|o|m| |l|e|f|t| | +0#0000000#ffffff0@31
+|4|9| @72
+>n|o|w| |w|o|r|k|i|n|g| |w|i|t|h| |s|o|m|e| |l+0&#5fd7ff255|o|n|g|e|r| +0&#ffffff0|t|e|x|t| |h|e|r|e| @36
+|5|1| @72
+|5|2| @6| +0#0000001#ffd7ff255|t|o|p| |r|i|g|h|t| | +0#0000000#ffffff0@9|╔+0#0000001#ffd7ff255|═@9|╗| +0#0000000#ffffff0@32
+|5|3| @27|║+0#0000001#ffd7ff255| |t|o|p| |l|e|f|t| |║| +0#0000000#ffffff0@32
+|5|4| @27|╚+0#0000001#ffd7ff255|═@9|╝| +0#0000000#ffffff0@32
+|5@1| @72
+@57|5|0|,|1| @9|4|9|%| 
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_popup_textprop_off_2.dump
@@ -0,0 +1,12 @@
+|4+0&#ffffff0|5| @72
+|4|6| @72
+|4|7| @72
+|4|8| @72
+|4|9| @72
+>n|o|w| |w|o|r|k|i|n|g| |w|i|t|h| |s|o|m|e| |l|o|n|g|e|r| |t|e|x|t| |h|e|r|e| @36
+|5|1| @72
+|5|2| @72
+|5|3| @72
+|5|4| @72
+|5@1| @72
+|:|c|a|l@1| |p|r|o|p|_|c|l|e|a|r|(|5|0|)| @36|5|0|,|1| @9|4|9|%| 
--- a/src/testdir/test_popupwin_textprop.vim
+++ b/src/testdir/test_popupwin_textprop.vim
@@ -45,6 +45,9 @@ func Test_textprop_popup()
   call term_sendkeys(buf, "k2dd")
   call VerifyScreenDump(buf, 'Test_popup_textprop_06', {})
 
+  call term_sendkeys(buf, "4\<C-E>")
+  call VerifyScreenDump(buf, 'Test_popup_textprop_07', {})
+
   " clean up
   call StopVimInTerminal(buf)
   call delete('XtestTextpropPopup')
@@ -99,10 +102,72 @@ func Test_textprop_popup_corners()
   call term_sendkeys(buf, ":\<CR>")
   call VerifyScreenDump(buf, 'Test_popup_textprop_corn_4', {})
 
+  call term_sendkeys(buf, ":vsplit foo\<CR>")
+  call VerifyScreenDump(buf, 'Test_popup_textprop_corn_5', {})
+
+  call term_sendkeys(buf, ":only!\<CR>")
+  call VerifyScreenDump(buf, 'Test_popup_textprop_corn_6', {})
+
   " clean up
   call StopVimInTerminal(buf)
   call delete('XtestTextpropPopupCorners')
 endfunc
 
+func Test_textprop_popup_offsets()
+  let lines =<< trim END
+	call setline(1, range(1, 100))
+	call setline(50, 'now working with some longer text here')
+	50
+	normal zz
+	set scrolloff=0
+	call prop_type_add('popupMarker', #{highlight: 'DiffAdd'})
+	call prop_add(50, 23, #{
+		\ length: 6,
+		\ type: 'popupMarker',
+		\ })
+	let winid = popup_create('bottom left', #{
+	      \ pos: 'botleft', 
+	      \ line: -1,
+	      \ col: 2,
+	      \ textprop: 'popupMarker',
+	      \ padding: [0,1,0,1],
+	      \ })
+	let winid = popup_create('bottom right', #{
+	      \ pos: 'botright', 
+	      \ line: -1,
+	      \ col: -2,
+	      \ textprop: 'popupMarker',
+	      \ border: [],
+	      \ padding: [0,1,0,1],
+	      \ })
+	let winid = popup_create('top left', #{
+	      \ pos: 'topleft', 
+	      \ line: 1,
+	      \ col: 2,
+	      \ textprop: 'popupMarker',
+	      \ border: [],
+	      \ padding: [0,1,0,1],
+	      \ })
+	let winid = popup_create('top right', #{
+	      \ pos: 'topright', 
+	      \ line: 1,
+	      \ col: -2,
+	      \ textprop: 'popupMarker',
+	      \ padding: [0,1,0,1],
+	      \ })
+  END
+  call writefile(lines, 'XtestTextpropPopupOffset')
+  let buf = RunVimInTerminal('-S XtestTextpropPopupOffset', #{rows: 12})
+  call VerifyScreenDump(buf, 'Test_popup_textprop_off_1', {})
+
+  " test that removing the text property closes the popups
+  call term_sendkeys(buf, ":call prop_clear(50)\<CR>")
+  call VerifyScreenDump(buf, 'Test_popup_textprop_off_2', {})
+
+  " clean up
+  call StopVimInTerminal(buf)
+  call delete('XtestTextpropPopupOffset')
+endfunc
+
 
 " vim: shiftwidth=2 sts=2
--- a/src/version.c
+++ b/src/version.c
@@ -762,6 +762,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1936,
+/**/
     1935,
 /**/
     1934,