Skip to content

Commit b754b5b

Browse files
committed
patch 8.1.2210: using negative offset for popup_create() does not work
Problem: Using negative offset for popup_create() does not work. Solution: Use -1 instead of zero. (closes #5111)
1 parent ec6f735 commit b754b5b

4 files changed

Lines changed: 38 additions & 20 deletions

File tree

src/popupwin.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ popup_options_one(dict_T *dict, char_u *key)
7171
else // "col"
7272
n = screen_screencol() + 1 + n;
7373

74-
if (n < 1)
75-
n = 1;
74+
// Zero means "not set", use -1 instead.
75+
if (n == 0)
76+
n = -1;
7677
return n;
7778
}
7879

@@ -222,7 +223,7 @@ popup_start_drag(win_T *wp, int row, int col)
222223
{
223224
drag_start_row = mouse_row;
224225
drag_start_col = mouse_col;
225-
if (wp->w_wantline == 0)
226+
if (wp->w_wantline <= 0)
226227
drag_start_wantline = wp->w_winrow + 1;
227228
else
228229
drag_start_wantline = wp->w_wantline;
@@ -1081,7 +1082,9 @@ popup_adjust_position(win_T *wp)
10811082
int org_leftoff = wp->w_popup_leftoff;
10821083
int minwidth;
10831084
int wantline = wp->w_wantline; // adjusted for textprop
1085+
int use_wantline = wantline != 0;
10841086
int wantcol = wp->w_wantcol; // adjusted for textprop
1087+
int use_wantcol = wantcol != 0;
10851088

10861089
wp->w_winrow = 0;
10871090
wp->w_wincol = 0;
@@ -1097,6 +1100,11 @@ popup_adjust_position(win_T *wp)
10971100
// If no line was specified default to vertical centering.
10981101
if (wantline == 0)
10991102
center_vert = TRUE;
1103+
else if (wantline < 0)
1104+
// If "wantline" is negative it actually means zero.
1105+
wantline = 0;
1106+
if (wantcol < 0)
1107+
wantcol = 0;
11001108

11011109
if (wp->w_popup_prop_type > 0 && win_valid(wp->w_popup_prop_win))
11021110
{
@@ -1161,15 +1169,15 @@ popup_adjust_position(win_T *wp)
11611169
}
11621170
else
11631171
{
1164-
if (wantline > 0 && (wp->w_popup_pos == POPPOS_TOPLEFT
1172+
if (use_wantline && (wp->w_popup_pos == POPPOS_TOPLEFT
11651173
|| wp->w_popup_pos == POPPOS_TOPRIGHT))
11661174
{
11671175
wp->w_winrow = wantline - 1;
11681176
if (wp->w_winrow >= Rows)
11691177
wp->w_winrow = Rows - 1;
11701178
}
11711179

1172-
if (wantcol == 0)
1180+
if (!use_wantcol)
11731181
center_hor = TRUE;
11741182
else if (wantcol > 0 && (wp->w_popup_pos == POPPOS_TOPLEFT
11751183
|| wp->w_popup_pos == POPPOS_BOTLEFT))
@@ -1372,8 +1380,8 @@ popup_adjust_position(win_T *wp)
13721380
// bottom aligned: may move down
13731381
wp->w_winrow = wantline - (wp->w_height + extra_height);
13741382
else
1375-
// not enough space, make top aligned
1376-
wp->w_winrow = wantline + 1;
1383+
// Not enough space, make top aligned.
1384+
wp->w_winrow = (wantline < 0 ? 0 : wantline) + 1;
13771385
}
13781386
if (wp->w_winrow >= Rows)
13791387
wp->w_winrow = Rows - 1;
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
|-+0&#ffffff0@59| @14
2-
|-@1|#|-@20|@|-@34| @14
3-
|-@1|╔+0#0000001#ffd7ff255|═@7|╗|-+0#0000000#ffffff0@2|╔+0#0000001#ffd7ff255|═@7|╗|-+0#0000000#ffffff0@2|╔+0#0000001#ffd7ff255|═@7|╗|-+0#0000000#ffffff0@2|╔+0#0000001#ffd7ff255|═@7|╗|-+0#0000000#ffffff0@8| @14
4-
|-@1|║+0#0000001#ffd7ff255| @7|║|-+0#0000000#ffffff0@2|║+0#0000001#ffd7ff255| @7|║|-+0#0000000#ffffff0@2|║+0#0000001#ffd7ff255| @7|║|-+0#0000000#ffffff0@2|║+0#0000001#ffd7ff255| @7|║|-+0#0000000#ffffff0@8| @14
5-
|-@1|║+0#0000001#ffd7ff255| |f|i|r|s|t| @1|║|-+0#0000000#ffffff0@2|║+0#0000001#ffd7ff255| |F|i|r|s|t| @1|║|-+0#0000000#ffffff0@2|║+0#0000001#ffd7ff255| |f|i|R|S|t| @1|║|-+0#0000000#ffffff0@2|║+0#0000001#ffd7ff255| |F|I|r|s|T| @1|║|-+0#0000000#ffffff0@8| @14
6-
|-@1|║+0#0000001#ffd7ff255| |s|e|c|o|n|d| |║|-+0#0000000#ffffff0@2|║+0#0000001#ffd7ff255| |S|e|c|o|n|D| |║|-+0#0000000#ffffff0@2|║+0#0000001#ffd7ff255| |s|e|C|O|n|d| |║|-+0#0000000#ffffff0@2|║+0#0000001#ffd7ff255| |S|E|c|o|N|D| |║|-+0#0000000#ffffff0@8| @14
7-
|-@1|║+0#0000001#ffd7ff255| @7|║|-+0#0000000#ffffff0@2|║+0#0000001#ffd7ff255| @7|║|-+0#0000000#ffffff0@2|║+0#0000001#ffd7ff255| @7|║|-+0#0000000#ffffff0@2|║+0#0000001#ffd7ff255| @7|║|-+0#0000000#ffffff0@8| @14
8-
|-@1|╚+0#0000001#ffd7ff255|═@7|╝|-+0#0000000#ffffff0@2|╚+0#0000001#ffd7ff255|═@7|╝|-+0#0000000#ffffff0@2|╚+0#0000001#ffd7ff255|═@7|╝|-+0#0000000#ffffff0@2|╚+0#0000001#ffd7ff255|═@7|╝|-+0#0000000#ffffff0@8| @14
9-
|-@27|%|-@20>&|-@8| @14
1+
|-+0&#ffffff0@49>*|-@8| @14
2+
|-@1|#|-@19|@|-@25|╔+0#0000001#ffd7ff255|═@4|╗|-+0#0000000#ffffff0@2| @14
3+
|-@1|╔+0#0000001#ffd7ff255|═@7|╗|-+0#0000000#ffffff0@1|╔+0#0000001#ffd7ff255|═@7|╗|-+0#0000000#ffffff0@1|╔+0#0000001#ffd7ff255|═@7|╗|-+0#0000000#ffffff0@1|╔+0#0000001#ffd7ff255|═@7|╗|-+0#0000000#ffffff0@1|║+0#0000001#ffd7ff255| @4|║|-+0#0000000#ffffff0@2| @14
4+
|-@1|║+0#0000001#ffd7ff255| @7|║|-+0#0000000#ffffff0@1|║+0#0000001#ffd7ff255| @7|║|-+0#0000000#ffffff0@1|║+0#0000001#ffd7ff255| @7|║|-+0#0000000#ffffff0@1|║+0#0000001#ffd7ff255| @7|║|-+0#0000000#ffffff0@1|║+0#0000001#ffd7ff255| |o|n|e| |║|-+0#0000000#ffffff0@2| @14
5+
|-@1|║+0#0000001#ffd7ff255| |f|i|r|s|t| @1|║|-+0#0000000#ffffff0@1|║+0#0000001#ffd7ff255| |F|i|r|s|t| @1|║|-+0#0000000#ffffff0@1|║+0#0000001#ffd7ff255| |f|i|R|S|t| @1|║|-+0#0000000#ffffff0@1|║+0#0000001#ffd7ff255| |F|I|r|s|T| @1|║|-+0#0000000#ffffff0@1|║+0#0000001#ffd7ff255| |t|w|o| |║|-+0#0000000#ffffff0@2| @14
6+
|-@1|║+0#0000001#ffd7ff255| |s|e|c|o|n|d| |║|-+0#0000000#ffffff0@1|║+0#0000001#ffd7ff255| |S|e|c|o|n|D| |║|-+0#0000000#ffffff0@1|║+0#0000001#ffd7ff255| |s|e|C|O|n|d| |║|-+0#0000000#ffffff0@1|║+0#0000001#ffd7ff255| |S|E|c|o|N|D| |║|-+0#0000000#ffffff0@1|║+0#0000001#ffd7ff255| @4|║|-+0#0000000#ffffff0@2| @14
7+
|-@1|║+0#0000001#ffd7ff255| @7|║|-+0#0000000#ffffff0@1|║+0#0000001#ffd7ff255| @7|║|-+0#0000000#ffffff0@1|║+0#0000001#ffd7ff255| @7|║|-+0#0000000#ffffff0@1|║+0#0000001#ffd7ff255| @7|║|-+0#0000000#ffffff0@1|╚+0#0000001#ffd7ff255|═@4|╝|-+0#0000000#ffffff0@2| @14
8+
|-@1|╚+0#0000001#ffd7ff255|═@7|╝|-+0#0000000#ffffff0@1|╚+0#0000001#ffd7ff255|═@7|╝|-+0#0000000#ffffff0@1|╚+0#0000001#ffd7ff255|═@7|╝|-+0#0000000#ffffff0@1|╚+0#0000001#ffd7ff255|═@7|╝|-+0#0000000#ffffff0@11| @14
9+
|-@25|%|-@19|&|-@11| @14
1010
|-@59| @14
1111
|-@59| @14
12-
@57|9|,|5|1| @9|T|o|p|
12+
@57|1|,|5|1| @9|T|o|p|

src/testdir/test_popupwin.vim

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,30 +278,38 @@ func Test_popup_all_corners()
278278
\ border: [],
279279
\ padding: [],
280280
\ })
281-
normal 25|r@
281+
normal 24|r@
282282
let winid1 = popup_create(['First', 'SeconD'], #{
283283
\ line: 'cursor+1',
284284
\ col: 'cursor',
285285
\ pos: 'topright',
286286
\ border: [],
287287
\ padding: [],
288288
\ })
289-
normal 9G29|r%
289+
normal 9G27|r%
290290
let winid1 = popup_create(['fiRSt', 'seCOnd'], #{
291291
\ line: 'cursor-1',
292292
\ col: 'cursor',
293293
\ pos: 'botleft',
294294
\ border: [],
295295
\ padding: [],
296296
\ })
297-
normal 51|r&
297+
normal 48|r&
298298
let winid1 = popup_create(['FIrsT', 'SEcoND'], #{
299299
\ line: 'cursor-1',
300300
\ col: 'cursor',
301301
\ pos: 'botright',
302302
\ border: [],
303303
\ padding: [],
304304
\ })
305+
normal 1G51|r*
306+
let winid1 = popup_create(['one', 'two'], #{
307+
\ line: 'cursor-1',
308+
\ col: 'cursor',
309+
\ pos: 'botleft',
310+
\ border: [],
311+
\ padding: [],
312+
\ })
305313
END
306314
call writefile(lines, 'XtestPopupCorners')
307315
let buf = RunVimInTerminal('-S XtestPopupCorners', #{rows: 12})

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,8 @@ static char *(features[]) =
741741

742742
static int included_patches[] =
743743
{ /* Add new patch number below this line */
744+
/**/
745+
2210,
744746
/**/
745747
2209,
746748
/**/

0 commit comments

Comments
 (0)