aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/popupmnu.c45
-rw-r--r--src/nvim/testdir/test_popup.vim22
-rw-r--r--test/functional/ui/popupmenu_spec.lua20
3 files changed, 52 insertions, 35 deletions
diff --git a/src/nvim/popupmnu.c b/src/nvim/popupmnu.c
index d53f2c2c7b..c9ff49d233 100644
--- a/src/nvim/popupmnu.c
+++ b/src/nvim/popupmnu.c
@@ -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 {
- pum_row = above_row;
- pum_height = row - above_row;
- }
+ // 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 = pum_win_row - above_row;
}
if (pum_external) {
return;
diff --git a/src/nvim/testdir/test_popup.vim b/src/nvim/testdir/test_popup.vim
index 9db6112eeb..27c90f9114 100644
--- a/src/nvim/testdir/test_popup.vim
+++ b/src/nvim/testdir/test_popup.vim
@@ -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
diff --git a/test/functional/ui/popupmenu_spec.lua b/test/functional/ui/popupmenu_spec.lua
index 13affac571..4c7f516c43 100644
--- a/test/functional/ui/popupmenu_spec.lua
+++ b/test/functional/ui/popupmenu_spec.lua
@@ -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} |