]> granicus.if.org Git - vim/commitdiff
patch 8.0.1491: the minimum width of the popup menu is hard coded v8.0.1491
authorBram Moolenaar <Bram@vim.org>
Sat, 10 Feb 2018 14:36:55 +0000 (15:36 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 10 Feb 2018 14:36:55 +0000 (15:36 +0100)
Problem:    The minimum width of the popup menu is hard coded.
Solution:   Add the 'pumwidth' option. (Christian Brabandt, James McCoy,
            closes #2314)

runtime/doc/options.txt
src/option.c
src/option.h
src/popupmnu.c
src/version.c

index 87b7bbc5003215b312106ab2f48acdc7635e5aad..b260d7e11d8d19067be62b54c52ca2d6b3313d1c 100644 (file)
@@ -5953,6 +5953,16 @@ A jump table for the options with a short description can be found at |Q_op|.
                        {not in Vi}
        Determines the maximum number of items to show in the popup menu for
        Insert mode completion.  When zero as much space as available is used.
+       |ins-completion-menu|.
+
+                                               *'pumwidth'* *'pw'*
+'pumwidth' 'pw'                number  (default 0)
+                       global
+                       {not available when compiled without the
+                       |+insert_expand| feature}
+                       {not in Vi}
+       Determines the minium width to use for the popup menu for Insert mode
+       completion.  When zero the default of 15 screen cells is used.
        |ins-completion-menu|.
 
                                                *'pythondll'*
index 4898e694c5e80456f35f402643afd4515f375445..5e215d52d58da5420eeee3c3e68077c4f36c00b9 100644 (file)
@@ -2237,6 +2237,13 @@ static struct vimoption options[] =
                            (char_u *)&p_ph, PV_NONE,
 #else
                            (char_u *)NULL, PV_NONE,
+#endif
+                           {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
+    {"pumwidth",    "pw",   P_NUM|P_VI_DEF,
+#ifdef FEAT_INS_EXPAND
+                           (char_u *)&p_pw, PV_NONE,
+#else
+                           (char_u *)NULL, PV_NONE,
 #endif
                            {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
     {"pythonthreedll",  NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
index 21be3a39f176ab069897dc3abe131ab205d58af0..5ced8fecd3614117b4dbc42d2d3fee578b13082c 100644 (file)
@@ -424,6 +424,7 @@ EXTERN int  p_cp;           /* 'compatible' */
 #ifdef FEAT_INS_EXPAND
 EXTERN char_u  *p_cot;         /* 'completeopt' */
 EXTERN long    p_ph;           /* 'pumheight' */
+EXTERN long    p_pw;           /* 'pumwidth' */
 #endif
 EXTERN char_u  *p_cpo;         /* 'cpoptions' */
 #ifdef FEAT_CSCOPE
index 447f789e5964a2e1a4d15c30909c32450c33c407..f53649f1232fb0875d118c905ad3222e2a1e56cb 100644 (file)
@@ -66,6 +66,15 @@ pum_compute_size(void)
     }
 }
 
+/*
+ * Return the minimum width of the popup menu.
+ */
+    static int
+pum_get_width(void)
+{
+    return p_pw == 0 ? PUM_DEF_WIDTH : p_pw;
+}
+
 /*
  * Show the popup menu with items "array[size]".
  * "array" must remain valid until pum_undisplay() is called!
@@ -93,7 +102,7 @@ pum_display(
 
     do
     {
-       def_width = PUM_DEF_WIDTH;
+       def_width = pum_get_width();
        above_row = 0;
        below_row = cmdline_row;
 
@@ -216,16 +225,17 @@ pum_display(
        if (def_width < max_width)
            def_width = max_width;
 
-       if (((col < Columns - PUM_DEF_WIDTH || col < Columns - max_width)
+       if (((col < Columns - pum_get_width() || col < Columns - max_width)
 #ifdef FEAT_RIGHTLEFT
                    && !curwin->w_p_rl)
-               || (curwin->w_p_rl && (col > PUM_DEF_WIDTH || col > max_width)
+              || (curwin->w_p_rl && (col > pum_get_width() || col > max_width)
 #endif
           ))
        {
            /* align pum column with "col" */
            pum_col = col;
 
+           /* start with the maximum space available */
 #ifdef FEAT_RIGHTLEFT
            if (curwin->w_p_rl)
                pum_width = pum_col - pum_scrollbar + 1;
@@ -234,12 +244,71 @@ pum_display(
                pum_width = Columns - pum_col - pum_scrollbar;
 
            if (pum_width > max_width + pum_kind_width + pum_extra_width + 1
-                                                 && pum_width > PUM_DEF_WIDTH)
+                                               && pum_width > pum_get_width())
            {
+               /* the width is too much, make it narrower */
                pum_width = max_width + pum_kind_width + pum_extra_width + 1;
-               if (pum_width < PUM_DEF_WIDTH)
-                   pum_width = PUM_DEF_WIDTH;
+               if (pum_width < pum_get_width())
+                   pum_width = pum_get_width();
            }
+           else if (((col > pum_get_width() || col > max_width)
+#ifdef FEAT_RIGHTLEFT
+                       && !curwin->w_p_rl)
+               || (curwin->w_p_rl && (col < Columns - pum_get_width()
+                       || col < Columns - max_width)
+#endif
+                   ))
+           {
+               /* align right pum edge with "col" */
+#ifdef FEAT_RIGHTLEFT
+               if (curwin->w_p_rl)
+               {
+                   pum_col = col + max_width + pum_scrollbar + 1;
+                   if (pum_col >= Columns)
+                       pum_col = Columns - 1;
+               }
+               else
+#endif
+               {
+                   pum_col = col - max_width - pum_scrollbar;
+                   if (pum_col < 0)
+                       pum_col = 0;
+               }
+
+#ifdef FEAT_RIGHTLEFT
+               if (curwin->w_p_rl)
+                   pum_width = W_ENDCOL(curwin) - pum_col - pum_scrollbar + 1;
+               else
+#endif
+                   pum_width = pum_col - pum_scrollbar;
+
+               if (pum_width < pum_get_width())
+               {
+                   pum_width = pum_get_width();
+#ifdef FEAT_RIGHTLEFT
+                   if (curwin->w_p_rl)
+                   {
+                       if (pum_width > pum_col)
+                           pum_width = pum_col;
+                   }
+                   else
+#endif
+                   {
+                       if (pum_width >= Columns - pum_col)
+                           pum_width = Columns - pum_col - 1;
+                   }
+               }
+               else if (pum_width > max_width + pum_kind_width
+                                                         + pum_extra_width + 1
+                           && pum_width > pum_get_width())
+               {
+                   pum_width = max_width + pum_kind_width
+                                                        + pum_extra_width + 1;
+                   if (pum_width < pum_get_width())
+                       pum_width = pum_get_width();
+               }
+           }
+
        }
        else if (Columns < def_width)
        {
@@ -254,8 +323,8 @@ pum_display(
        }
        else
        {
-           if (max_width > PUM_DEF_WIDTH)
-               max_width = PUM_DEF_WIDTH;      /* truncate */
+           if (max_width > pum_get_width())
+               max_width = pum_get_width();    /* truncate */
 #ifdef FEAT_RIGHTLEFT
            if (curwin->w_p_rl)
                pum_col = max_width - 1;
@@ -1005,4 +1074,5 @@ ui_may_remove_balloon(void)
        ui_remove_balloon();
 }
 # endif
+
 #endif
index 0a5475189581ea3445b089475f30abb3dc9096bc..1bd029555aff8d20a5dc7cad5ffa4ebec36b3cbd 100644 (file)
@@ -771,6 +771,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1491,
 /**/
     1490,
 /**/