0
0
mirror of https://github.com/vim/vim.git synced 2025-09-28 04:24:06 -04:00

patch 8.1.1450: popup window positioning wrong when using padding or borders

Problem:    Popup window positioning wrong when using padding or borders.
Solution:   Fix computing the position.
This commit is contained in:
Bram Moolenaar
2019-06-02 15:34:29 +02:00
parent 042fb4b449
commit 399d898ac1
4 changed files with 73 additions and 4 deletions

View File

@@ -382,6 +382,12 @@ popup_adjust_position(win_T *wp)
int center_vert = FALSE; int center_vert = FALSE;
int center_hor = FALSE; int center_hor = FALSE;
int allow_adjust_left = !wp->w_popup_fixed; int allow_adjust_left = !wp->w_popup_fixed;
int top_extra = wp->w_popup_border[0] + wp->w_popup_padding[0];
int right_extra = wp->w_popup_border[1] + wp->w_popup_padding[1];
int bot_extra = wp->w_popup_border[2] + wp->w_popup_padding[2];
int left_extra = wp->w_popup_border[3] + wp->w_popup_padding[3];
int extra_height = top_extra + bot_extra;
int extra_width = left_extra + right_extra;
wp->w_winrow = 0; wp->w_winrow = 0;
wp->w_wincol = 0; wp->w_wincol = 0;
@@ -474,8 +480,8 @@ popup_adjust_position(win_T *wp)
{ {
// Right aligned: move to the right if needed. // Right aligned: move to the right if needed.
// No truncation, because that would change the height. // No truncation, because that would change the height.
if (wp->w_width < wp->w_wantcol) if (wp->w_width + extra_width < wp->w_wantcol)
wp->w_wincol = wp->w_wantcol - wp->w_width; wp->w_wincol = wp->w_wantcol - (wp->w_width + extra_width);
} }
if (wp->w_height <= 1) if (wp->w_height <= 1)
@@ -492,9 +498,9 @@ popup_adjust_position(win_T *wp)
else if (wp->w_popup_pos == POPPOS_BOTRIGHT else if (wp->w_popup_pos == POPPOS_BOTRIGHT
|| wp->w_popup_pos == POPPOS_BOTLEFT) || wp->w_popup_pos == POPPOS_BOTLEFT)
{ {
if (wp->w_height <= wp->w_wantline) if ((wp->w_height + extra_height) <= wp->w_wantline)
// bottom aligned: may move down // bottom aligned: may move down
wp->w_winrow = wp->w_wantline - wp->w_height; wp->w_winrow = wp->w_wantline - (wp->w_height + extra_height);
else else
// not enough space, make top aligned // not enough space, make top aligned
wp->w_winrow = wp->w_wantline + 1; wp->w_winrow = wp->w_wantline + 1;

View File

@@ -0,0 +1,12 @@
|-+0&#ffffff0@59| @14
|-@1|#|-@20|@|-@34| @14
|-@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
|-@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
|-@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
|-@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
|-@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
|-@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
|-@27|%|-@20>&|-@8| @14
|-@59| @14
|-@59| @14
@57|9|,|5|1| @9|T|o|p|

View File

@@ -175,6 +175,55 @@ func Test_popup_with_syntax_setbufvar()
call delete('XtestPopup') call delete('XtestPopup')
endfunc endfunc
func Test_popup_all_corners()
if !CanRunVimInTerminal()
return
endif
let lines =<< trim END
call setline(1, repeat([repeat('-', 60)], 15))
set so=0
normal 2G3|r#
let winid1 = popup_create(['first', 'second'], {
\ 'line': 'cursor+1',
\ 'col': 'cursor',
\ 'pos': 'topleft',
\ 'border': [],
\ 'padding': [],
\ })
normal 25|r@
let winid1 = popup_create(['First', 'SeconD'], {
\ 'line': 'cursor+1',
\ 'col': 'cursor',
\ 'pos': 'topright',
\ 'border': [],
\ 'padding': [],
\ })
normal 9G29|r%
let winid1 = popup_create(['fiRSt', 'seCOnd'], {
\ 'line': 'cursor-1',
\ 'col': 'cursor',
\ 'pos': 'botleft',
\ 'border': [],
\ 'padding': [],
\ })
normal 51|r&
let winid1 = popup_create(['FIrsT', 'SEcoND'], {
\ 'line': 'cursor-1',
\ 'col': 'cursor',
\ 'pos': 'botright',
\ 'border': [],
\ 'padding': [],
\ })
END
call writefile(lines, 'XtestPopupCorners')
let buf = RunVimInTerminal('-S XtestPopupCorners', {'rows': 12})
call VerifyScreenDump(buf, 'Test_popupwin_corners', {})
" clean up
call StopVimInTerminal(buf)
call delete('XtestPopupCorners')
endfunc
func Test_win_execute_closing_curwin() func Test_win_execute_closing_curwin()
split split
let winid = popup_create('some text', {}) let winid = popup_create('some text', {})

View File

@@ -767,6 +767,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1450,
/**/ /**/
1449, 1449,
/**/ /**/