]> granicus.if.org Git - vim/commitdiff
patch 8.1.1936: not enough tests for text property popup window v8.1.1936
authorBram Moolenaar <Bram@vim.org>
Thu, 29 Aug 2019 18:02:11 +0000 (20:02 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 29 Aug 2019 18:02:11 +0000 (20:02 +0200)
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.

src/popupwin.c
src/testdir/dumps/Test_popup_textprop_07.dump [new file with mode: 0644]
src/testdir/dumps/Test_popup_textprop_corn_5.dump [new file with mode: 0644]
src/testdir/dumps/Test_popup_textprop_corn_6.dump [new file with mode: 0644]
src/testdir/dumps/Test_popup_textprop_off_1.dump [new file with mode: 0644]
src/testdir/dumps/Test_popup_textprop_off_2.dump [new file with mode: 0644]
src/testdir/test_popupwin_textprop.vim
src/version.c

index 4dadee6ef038370c3d37851193e4e25db037dac8..dfc0c89de9fae370184c51f3b4463dee04badac8 100644 (file)
@@ -33,6 +33,7 @@ static void popup_adjust_position(win_T *wp);
 /*
  * 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 *key)
 
     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;
+    int            round;
+    win_T   *wp;
+    win_T   *next;
+    int            ret = FALSE;
 
-    for (wp = first_popupwin; wp != NULL; wp = wp->w_next)
-       if (wp->w_popup_prop_win == win)
-       {
-           popup_close_with_retval(wp, -1);
-           return TRUE;
-       }
-    for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next)
-       if (wp->w_popup_prop_win == win)
+    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;
+           }
        }
-    return FALSE;
+    return ret;
 }
 
 /*
diff --git a/src/testdir/dumps/Test_popup_textprop_07.dump b/src/testdir/dumps/Test_popup_textprop_07.dump
new file mode 100644 (file)
index 0000000..2950ddc
--- /dev/null
@@ -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|%| 
diff --git a/src/testdir/dumps/Test_popup_textprop_corn_5.dump b/src/testdir/dumps/Test_popup_textprop_corn_5.dump
new file mode 100644 (file)
index 0000000..c79e898
--- /dev/null
@@ -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
diff --git a/src/testdir/dumps/Test_popup_textprop_corn_6.dump b/src/testdir/dumps/Test_popup_textprop_corn_6.dump
new file mode 100644 (file)
index 0000000..7e6426c
--- /dev/null
@@ -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| 
diff --git a/src/testdir/dumps/Test_popup_textprop_off_1.dump b/src/testdir/dumps/Test_popup_textprop_off_1.dump
new file mode 100644 (file)
index 0000000..33f2978
--- /dev/null
@@ -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|%| 
diff --git a/src/testdir/dumps/Test_popup_textprop_off_2.dump b/src/testdir/dumps/Test_popup_textprop_off_2.dump
new file mode 100644 (file)
index 0000000..1896c64
--- /dev/null
@@ -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|%| 
index 2a4eb2cd0d6449c9b6d3a6a0e4196102be4e8b5b..8a68f15d7e13d708b3ef2c75ad18e33415cc2754 100644 (file)
@@ -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
index f798b8f4ba622c6a33a580bd4e9e35c5495be256..2151002f48fc670617d16f5eefcba695a9a734b9 100644 (file)
@@ -761,6 +761,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1936,
 /**/
     1935,
 /**/