]> granicus.if.org Git - vim/commitdiff
patch 8.1.1904: cannot have an info popup align with the popup menu v8.1.1904
authorBram Moolenaar <Bram@vim.org>
Wed, 21 Aug 2019 15:29:29 +0000 (17:29 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 21 Aug 2019 15:29:29 +0000 (17:29 +0200)
Problem:    Cannot have an info popup align with the popup menu.
Solution:   Add the "align" item to 'completepopup'.

runtime/doc/insert.txt
src/popupmnu.c
src/popupwin.c
src/testdir/dumps/Test_popupwin_infopopup_align_1.dump [new file with mode: 0644]
src/testdir/dumps/Test_popupwin_infopopup_align_2.dump [new file with mode: 0644]
src/testdir/dumps/Test_popupwin_infopopup_align_3.dump [new file with mode: 0644]
src/testdir/test_popupwin.vim
src/version.c
src/vim.h

index 87407e160c8a5694f80ff9bbd0ec27570d9a1044..43b6d65f4cd3a746bc226bfcf8cf3d881e47baaa 100644 (file)
@@ -1124,9 +1124,16 @@ option is a comma separated list of values:
        height          maximum height of the popup
        width           maximum width of the popup
        highlight       highlight group of the popup (default is Pmenu)
+       align           "item" (default) or "menu"
+       border          "on" (default) or "off"
 Example: >
        :set completepopup=height:10,width:60,highlight:InfoPopup
 
+When the "align" value is "item then the popup is positioned close to the
+selected item.  Changing the selection will also move the popup.  When "align"
+is "menu" then the popup is aligned with the top of the menu if the menu is
+below the text, and the bottom of the menu otherwise.
+
 The "kind" item uses a single letter to indicate the kind of completion.  This
 may be used to show the completion differently (different color or icon).
 Currently these types can be used:
index 5b76da582f2bec4c42fc8fb4b9a52c96561bf427..8f35ee5454895c85f1ee04e988bdbb6a6b18c33c 100644 (file)
@@ -745,18 +745,38 @@ pum_set_selected(int n, int repeat UNUSED)
                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
index a803faac105daace856dddd32bec648f0ba27948..b8fc8fdf219edf5017972745d61d22df6e6d9b89 100644 (file)
@@ -1300,6 +1300,9 @@ parse_popup_option(win_T *wp, int is_preview)
 #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 @@ parse_popup_option(win_T *wp, int is_preview)
                    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 (file)
index 0000000..20c9790
--- /dev/null
@@ -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 (file)
index 0000000..6b4a4e0
--- /dev/null
@@ -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 (file)
index 0000000..6effda0
--- /dev/null
@@ -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
index 98522b792f94af6c7b8a6c3ac30ae371bda33e2d..1f1f7314b41096a45c3a8be34240e3d0f4fc4158 100644 (file)
@@ -2292,4 +2292,33 @@ func Test_popupmenu_info_noborder()
   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
index 56f69723bb2f0a1c55c23a9128f8d6cc753cbb00..6c8bd8983177b6adb196008f2c95c3a41daf3072 100644 (file)
@@ -761,6 +761,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1904,
 /**/
     1903,
 /**/
index 4a861779e55cec68d8e52605713fef41786219a3..6d89f03ab32eb95ec63c6f43b5886db999962e8c 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
@@ -623,6 +623,7 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
 #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)