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

View File

@@ -733,6 +733,28 @@ func Test_popup_and_preview_autocommand()
bw! bw!
endfunc 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() func Test_popup_position()
if !CanRunVimInTerminal() if !CanRunVimInTerminal()
return return

View File

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