vim-patch:8.1.0554: popup menu overlaps with preview window

Problem:    Popup menu overlaps with preview window.
Solution:   Adjust the height computation. (Hirohito Higashi, closes vim/vim#3414)
614ab8aa00

Cherry-picked "row -> pum_win_row" rename changes from patch 8.1.0062.
This commit is contained in:
Jan Edmund Lazo
2019-12-26 13:21:35 -05:00
parent 51c9e3c4d1
commit 1d3d84fe81
3 changed files with 52 additions and 35 deletions

View File

@@ -100,7 +100,7 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed,
int above_row;
int below_row;
int redo_count = 0;
int row;
int pum_win_row;
int col;
if (!pum_is_visible) {
@@ -121,12 +121,12 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed,
// wildoptions=pum
if (State == CMDLINE) {
row = ui_has(kUICmdline) ? 0 : cmdline_row;
pum_win_row = ui_has(kUICmdline) ? 0 : cmdline_row;
col = cmd_startcol;
pum_anchor_grid = ui_has(kUICmdline) ? -1 : DEFAULT_GRID_HANDLE;
} else {
// anchor position: the start of the completed word
row = curwin->w_wrow;
pum_win_row = curwin->w_wrow;
if (curwin->w_p_rl) {
col = curwin->w_width - curwin->w_wcol - 1;
} else {
@@ -136,7 +136,7 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed,
pum_anchor_grid = (int)curwin->w_grid.handle;
if (!ui_has(kUIMultigrid)) {
pum_anchor_grid = (int)default_grid.handle;
row += curwin->w_winrow;
pum_win_row += curwin->w_winrow;
col += curwin->w_wincol;
}
}
@@ -152,7 +152,8 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed,
ADD(item, STRING_OBJ(cstr_to_string((char *)array[i].pum_info)));
ADD(arr, ARRAY_OBJ(item));
}
ui_call_popupmenu_show(arr, selected, row, col, pum_anchor_grid);
ui_call_popupmenu_show(arr, selected, pum_win_row, col,
pum_anchor_grid);
} else {
ui_call_popupmenu_select(selected);
return;
@@ -188,11 +189,11 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed,
pum_height = (int)p_ph;
}
// Put the pum below "row" if possible. If there are few lines decide on
// where there is more room.
if (row + 2 >= below_row - pum_height
&& row - above_row > (below_row - above_row) / 2) {
// pum above "row"
// Put the pum below "pum_win_row" if possible.
// If there are few lines decide on where there is more room.
if (pum_win_row + 2 >= below_row - pum_height
&& pum_win_row - above_row > (below_row - above_row) / 2) {
// pum above "pum_win_row"
pum_above = true;
// Leave two lines of context if possible
@@ -202,12 +203,12 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed,
context_lines = curwin->w_wrow - curwin->w_cline_row;
}
if (row >= size + context_lines) {
pum_row = row - size - context_lines;
if (pum_win_row >= size + context_lines) {
pum_row = pum_win_row - size - context_lines;
pum_height = size;
} else {
pum_row = 0;
pum_height = row - context_lines;
pum_height = pum_win_row - context_lines;
}
if ((p_ph > 0) && (pum_height > p_ph)) {
@@ -215,7 +216,7 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed,
pum_height = (int)p_ph;
}
} else {
// pum below "row"
// pum below "pum_win_row"
pum_above = false;
// Leave two lines of context if possible
@@ -226,7 +227,7 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed,
+ curwin->w_cline_height - curwin->w_wrow;
}
pum_row = row + context_lines;
pum_row = pum_win_row + context_lines;
if (size > below_row - pum_row) {
pum_height = below_row - pum_row;
} else {
@@ -243,16 +244,10 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed,
return;
}
// If there is a preview window above, avoid drawing over it.
// Do keep at least 10 entries.
if (pvwin != NULL && pum_row < above_row && pum_height > 10) {
if (row - above_row < 10) {
pum_row = row - 10;
pum_height = 10;
} else {
// If there is a preview window above avoid drawing over it.
if (pvwin != NULL && pum_row < above_row && pum_height > above_row) {
pum_row = above_row;
pum_height = row - above_row;
}
pum_height = pum_win_row - above_row;
}
if (pum_external) {
return;

View File

@@ -733,6 +733,28 @@ func Test_popup_and_preview_autocommand()
bw!
endfunc
func Test_popup_and_previewwindow_dump()
if !CanRunVimInTerminal()
return
endif
call writefile([
\ 'set previewheight=9',
\ 'silent! pedit',
\ 'call setline(1, map(repeat(["ab"], 10), "v:val. v:key"))',
\ 'exec "norm! G\<C-E>\<C-E>"',
\ ], 'Xscript')
let buf = RunVimInTerminal('-S Xscript', {})
" Test that popup and previewwindow do not overlap.
call term_sendkeys(buf, "o\<C-X>\<C-N>")
sleep 100m
call VerifyScreenDump(buf, 'Test_popup_and_previewwindow_01', {})
call term_sendkeys(buf, "\<Esc>u")
call StopVimInTerminal(buf)
call delete('Xscript')
endfunc
func Test_popup_position()
if !CanRunVimInTerminal()
return

View File

@@ -739,16 +739,16 @@ describe('builtin popupmenu', function()
ee |
ff |
gg |
{s:aa } |
{n:bb }{3:iew][+] }|
{n:cc } |
{n:dd } |
{n:ee } |
{n:ff } |
{n:gg } |
{n:hh } |
{n:ii } |
{n:jj } |
hh |
{s:aa }{c: }{3:ew][+] }|
{n:bb }{c: } |
{n:cc }{c: } |
{n:dd }{c: } |
{n:ee }{c: } |
{n:ff }{c: } |
{n:gg }{c: } |
{n:hh }{c: } |
{n:ii }{s: } |
aa^ |
{4:[No Name] [+] }|
{2:-- }{5:match 1 of 10} |