patch 8.1.1904: cannot have an info popup align with the popup menu
Problem: Cannot have an info popup align with the popup menu.
Solution: Add the "align" item to 'completepopup'.
diff --git a/src/popupmnu.c b/src/popupmnu.c
index 5b76da5..8f35ee5 100644
--- a/src/popupmnu.c
+++ b/src/popupmnu.c
@@ -745,18 +745,38 @@
if (use_popup)
{
int col = pum_col + pum_width + 1;
- int row = pum_row + pum_selected - pum_first + 1;
+ int row = pum_row;
+ int botpos = POPPOS_BOTLEFT;
+ curwin->w_popup_pos = POPPOS_TOPLEFT;
if (Columns - col < 20 && Columns - col < pum_col)
{
col = pum_col - 1;
curwin->w_popup_pos = POPPOS_TOPRIGHT;
+ botpos = POPPOS_BOTRIGHT;
curwin->w_maxwidth = pum_col - 1;
}
else
curwin->w_maxwidth = Columns - col + 1;
curwin->w_maxwidth -= popup_extra_width(curwin);
+
row -= popup_top_extra(curwin);
+ if (curwin->w_popup_flags & POPF_INFO_MENU)
+ {
+ if (pum_row < pum_win_row)
+ {
+ // menu above cursor line, align with bottom
+ row += pum_height;
+ curwin->w_popup_pos = botpos;
+ }
+ else
+ // menu below cursor line, align with top
+ row += 1;
+ }
+ else
+ // align with the selected item
+ row += pum_selected - pum_first + 1;
+
popup_set_wantpos_rowcol(curwin, row, col);
}
# endif
diff --git a/src/popupwin.c b/src/popupwin.c
index a803faa..b8fc8fd 100644
--- a/src/popupwin.c
+++ b/src/popupwin.c
@@ -1300,6 +1300,9 @@
#endif
p_pvp;
+ if (wp != NULL)
+ wp->w_popup_flags &= ~POPF_INFO_MENU;
+
for ( ; *p != NUL; p += (*p == ',' ? 1 : 0))
{
char_u *e, *dig;
@@ -1368,6 +1371,17 @@
wp->w_popup_close = POPCLOSE_NONE;
}
}
+ else if (STRNCMP(s, "align:", 6) == 0)
+ {
+ char_u *arg = s + 6;
+ int item = STRNCMP(arg, "item", 4) == 0 && arg + 4 == p;
+ int menu = STRNCMP(arg, "menu", 4) == 0 && arg + 4 == p;
+
+ if (!menu && !item)
+ return FAIL;
+ if (wp != NULL && menu)
+ wp->w_popup_flags |= POPF_INFO_MENU;
+ }
else
return FAIL;
}
diff --git a/src/testdir/dumps/Test_popupwin_infopopup_align_1.dump b/src/testdir/dumps/Test_popupwin_infopopup_align_1.dump
new file mode 100644
index 0000000..20c9790
--- /dev/null
+++ b/src/testdir/dumps/Test_popupwin_infopopup_align_1.dump
@@ -0,0 +1,14 @@
+|t+0&#ffffff0|e|x|t| |t|e|x|t| |t|e|x|t| |t|e|x|t| |t|e|x|t| |t@1|h|a|t|w|o|r|d> @40
+|~+0#4040ff13&| @23| +0#0000001#ffd7ff255|w|r|d| @4|W| |e|x|t|r|a| |t|e|x|t| | +0&#e0e0e08|t|h|a|t| |w|o|r|d| |i|s| |c|o@1|l| | +0#4040ff13#ffffff0@8
+|~| @23| +0#0000001#ffd7ff255|a|n|o|t|w|r|d| |W| |e|x|t|r|a| |t|e|x|t| | +0#4040ff13#ffffff0@27
+|~| @23| +0#0000001#ffd7ff255|n|o|a|w|r|d| @1|W| |e|x|t|r|a| |t|e|x|t| | +0#4040ff13#ffffff0@27
+|~| @23| +0#0000001#e0e0e08|t|h|a|t|w|r|d| |W| |e|x|t|r|a| |t|e|x|t| | +0#4040ff13#ffffff0@27
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|-+2#0000000&@1| |U|s|e|r| |d|e|f|i|n|e|d| |c|o|m|p|l|e|t|i|o|n| |(|^|U|^|N|^|P|)| |m+0#00e0003&|a|t|c|h| |4| |o|f| |4| +0#0000000&@26
diff --git a/src/testdir/dumps/Test_popupwin_infopopup_align_2.dump b/src/testdir/dumps/Test_popupwin_infopopup_align_2.dump
new file mode 100644
index 0000000..6b4a4e0
--- /dev/null
+++ b/src/testdir/dumps/Test_popupwin_infopopup_align_2.dump
@@ -0,0 +1,14 @@
+|t+0&#ffffff0|e|x|t| |t|e|x|t| |t|e|x|t| |t|e|x|t| |t|e|x|t| |t@1|h|a|t|w|o|r|d|t|e|s|t| |t|e|x|t| |t|e|s|t| |a|n|o|t|h|e|r|w|o|r|d> @14
+|~+0#4040ff13&| @9| +0#0000001#e0e0e08|o|t|h|e|r| |w|o|r|d|s| |a|r|e| @20| +0&#ffd7ff255|w|r|d| @4|W| |e|x|t|r|a| |t|e|x|t| | +0#4040ff13#ffffff0@4
+|~| @9| +0#0000001#e0e0e08|c|o@1|l|e|r| |t|h|a|n| |t|h|i|s| |a|n|d| |s|o|m|e| |m|o|r|e| |t|e|x|t| @1|a|n|o|t|w|r|d| |W| |e|x|t|r|a| |t|e|x|t| | +0#4040ff13#ffffff0@4
+|~| @9| +0#0000001#e0e0e08|t|o| |m|a|k|e| |w|r|a|p| @23| +0&#ffd7ff255|n|o|a|w|r|d| @1|W| |e|x|t|r|a| |t|e|x|t| | +0#4040ff13#ffffff0@4
+|~| @46| +0#0000001#ffd7ff255|t|h|a|t|w|r|d| |W| |e|x|t|r|a| |t|e|x|t| | +0#4040ff13#ffffff0@4
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|-+2#0000000&@1| |U|s|e|r| |d|e|f|i|n|e|d| |c|o|m|p|l|e|t|i|o|n| |(|^|U|^|N|^|P|)| |m+0#00e0003&|a|t|c|h| |2| |o|f| |4| +0#0000000&@26
diff --git a/src/testdir/dumps/Test_popupwin_infopopup_align_3.dump b/src/testdir/dumps/Test_popupwin_infopopup_align_3.dump
new file mode 100644
index 0000000..6effda0
--- /dev/null
+++ b/src/testdir/dumps/Test_popupwin_infopopup_align_3.dump
@@ -0,0 +1,14 @@
+|t+0&#ffffff0|e|x|t| |t|e|x|t| |t|e|x|t| |t|e|x|t| |t|e|x|t| |t@1|h|a|t|w|o|r|d|t|e|s|t| |t|e|x|t| |t|e|s|t| |a|n|o|t|h|e|r|w|o|r|d| @14
+|x| @73
+|x| @73
+|x| @73
+|x| @73
+|x| @73
+|x| @73
+|x| @7| +0#0000001#e0e0e08|w|r|d| @4|W| |e|x|t|r|a| |t|e|x|t| | +0#0000000#ffffff0@43
+|x| @7| +0#0000001#ffd7ff255|a|n|o|t|w|r|d| |W| |e|x|t|r|a| |t|e|x|t| | +0#0000000#ffffff0@43
+|x| @7| +0#0000001#ffd7ff255|n|o|a|w|r|d| @1|W| |e|x|t|r|a| |t|e|x|t| | +0#0000000#ffffff0@43
+|x| @7| +0#0000001#ffd7ff255|t|h|a|t|w|r|d| |W| |e|x|t|r|a| |t|e|x|t| | +0&#e0e0e08|w|o|r|d|s| |a|r|e| |c|o@1|l| | +0#0000000#ffffff0@27
+|t|e|s|t| |t|e|x|t| |a|w|o|r|d> @59
+|~+0#4040ff13&| @73
+|-+2#0000000&@1| |U|s|e|r| |d|e|f|i|n|e|d| |c|o|m|p|l|e|t|i|o|n| |(|^|U|^|N|^|P|)| |m+0#00e0003&|a|t|c|h| |1| |o|f| |4| +0#0000000&@26
diff --git a/src/testdir/test_popupwin.vim b/src/testdir/test_popupwin.vim
index 98522b7..1f1f731 100644
--- a/src/testdir/test_popupwin.vim
+++ b/src/testdir/test_popupwin.vim
@@ -2292,4 +2292,33 @@
call delete('XtestInfoPopupNb')
endfunc
+func Test_popupmenu_info_align_menu()
+ CheckScreendump
+
+ let lines = Get_popupmenu_lines()
+ call add(lines, 'set completepopup=height:4,border:off,align:menu')
+ call writefile(lines, 'XtestInfoPopupNb')
+
+ let buf = RunVimInTerminal('-S XtestInfoPopupNb', #{rows: 14})
+ call term_wait(buf, 50)
+
+ call term_sendkeys(buf, "A\<C-X>\<C-U>")
+ call term_sendkeys(buf, "\<C-N>")
+ call term_sendkeys(buf, "\<C-N>")
+ call term_sendkeys(buf, "\<C-N>")
+ call VerifyScreenDump(buf, 'Test_popupwin_infopopup_align_1', {})
+
+ call term_sendkeys(buf, "test text test text test\<C-X>\<C-U>")
+ call term_sendkeys(buf, "\<C-N>")
+ call VerifyScreenDump(buf, 'Test_popupwin_infopopup_align_2', {})
+
+ call term_sendkeys(buf, "\<Esc>")
+ call term_sendkeys(buf, ":call setline(2, ['x']->repeat(10))\<CR>")
+ call term_sendkeys(buf, "Gotest text test text\<C-X>\<C-U>")
+ call VerifyScreenDump(buf, 'Test_popupwin_infopopup_align_3', {})
+
+ call StopVimInTerminal(buf)
+ call delete('XtestInfoPopupNb')
+endfunc
+
" vim: shiftwidth=2 sts=2
diff --git a/src/version.c b/src/version.c
index 56f6972..6c8bd89 100644
--- a/src/version.c
+++ b/src/version.c
@@ -762,6 +762,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1904,
+/**/
1903,
/**/
1902,
diff --git a/src/vim.h b/src/vim.h
index 4a86177..6d89f03 100644
--- a/src/vim.h
+++ b/src/vim.h
@@ -623,6 +623,7 @@
#define POPF_RESIZE 0x40 // popup can be resized by dragging
#define POPF_MAPPING 0x80 // mapping keys
#define POPF_INFO 0x100 // used for info of popup menu
+#define POPF_INFO_MENU 0x200 // align info popup with popup menu
#ifdef FEAT_TEXT_PROP
# define WIN_IS_POPUP(wp) ((wp)->w_popup_flags != 0)