Skip to content

Commit a8f04aa

Browse files
committed
patch 8.0.1491: the minimum width of the popup menu is hard coded
Problem: The minimum width of the popup menu is hard coded. Solution: Add the 'pumwidth' option. (Christian Brabandt, James McCoy, closes #2314)
1 parent 2993ac5 commit a8f04aa

File tree

5 files changed

+98
-8
lines changed

5 files changed

+98
-8
lines changed

runtime/doc/options.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5953,6 +5953,16 @@ A jump table for the options with a short description can be found at |Q_op|.
59535953
{not in Vi}
59545954
Determines the maximum number of items to show in the popup menu for
59555955
Insert mode completion. When zero as much space as available is used.
5956+
|ins-completion-menu|.
5957+
5958+
*'pumwidth'* *'pw'*
5959+
'pumwidth' 'pw' number (default 0)
5960+
global
5961+
{not available when compiled without the
5962+
|+insert_expand| feature}
5963+
{not in Vi}
5964+
Determines the minium width to use for the popup menu for Insert mode
5965+
completion. When zero the default of 15 screen cells is used.
59565966
|ins-completion-menu|.
59575967

59585968
*'pythondll'*

src/option.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,6 +2237,13 @@ static struct vimoption options[] =
22372237
(char_u *)&p_ph, PV_NONE,
22382238
#else
22392239
(char_u *)NULL, PV_NONE,
2240+
#endif
2241+
{(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2242+
{"pumwidth", "pw", P_NUM|P_VI_DEF,
2243+
#ifdef FEAT_INS_EXPAND
2244+
(char_u *)&p_pw, PV_NONE,
2245+
#else
2246+
(char_u *)NULL, PV_NONE,
22402247
#endif
22412248
{(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
22422249
{"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,

src/option.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ EXTERN int p_cp; /* 'compatible' */
424424
#ifdef FEAT_INS_EXPAND
425425
EXTERN char_u *p_cot; /* 'completeopt' */
426426
EXTERN long p_ph; /* 'pumheight' */
427+
EXTERN long p_pw; /* 'pumwidth' */
427428
#endif
428429
EXTERN char_u *p_cpo; /* 'cpoptions' */
429430
#ifdef FEAT_CSCOPE

src/popupmnu.c

Lines changed: 78 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ pum_compute_size(void)
6666
}
6767
}
6868

69+
/*
70+
* Return the minimum width of the popup menu.
71+
*/
72+
static int
73+
pum_get_width(void)
74+
{
75+
return p_pw == 0 ? PUM_DEF_WIDTH : p_pw;
76+
}
77+
6978
/*
7079
* Show the popup menu with items "array[size]".
7180
* "array" must remain valid until pum_undisplay() is called!
@@ -93,7 +102,7 @@ pum_display(
93102

94103
do
95104
{
96-
def_width = PUM_DEF_WIDTH;
105+
def_width = pum_get_width();
97106
above_row = 0;
98107
below_row = cmdline_row;
99108

@@ -216,16 +225,17 @@ pum_display(
216225
if (def_width < max_width)
217226
def_width = max_width;
218227

219-
if (((col < Columns - PUM_DEF_WIDTH || col < Columns - max_width)
228+
if (((col < Columns - pum_get_width() || col < Columns - max_width)
220229
#ifdef FEAT_RIGHTLEFT
221230
&& !curwin->w_p_rl)
222-
|| (curwin->w_p_rl && (col > PUM_DEF_WIDTH || col > max_width)
231+
|| (curwin->w_p_rl && (col > pum_get_width() || col > max_width)
223232
#endif
224233
))
225234
{
226235
/* align pum column with "col" */
227236
pum_col = col;
228237

238+
/* start with the maximum space available */
229239
#ifdef FEAT_RIGHTLEFT
230240
if (curwin->w_p_rl)
231241
pum_width = pum_col - pum_scrollbar + 1;
@@ -234,12 +244,71 @@ pum_display(
234244
pum_width = Columns - pum_col - pum_scrollbar;
235245

236246
if (pum_width > max_width + pum_kind_width + pum_extra_width + 1
237-
&& pum_width > PUM_DEF_WIDTH)
247+
&& pum_width > pum_get_width())
238248
{
249+
/* the width is too much, make it narrower */
239250
pum_width = max_width + pum_kind_width + pum_extra_width + 1;
240-
if (pum_width < PUM_DEF_WIDTH)
241-
pum_width = PUM_DEF_WIDTH;
251+
if (pum_width < pum_get_width())
252+
pum_width = pum_get_width();
242253
}
254+
else if (((col > pum_get_width() || col > max_width)
255+
#ifdef FEAT_RIGHTLEFT
256+
&& !curwin->w_p_rl)
257+
|| (curwin->w_p_rl && (col < Columns - pum_get_width()
258+
|| col < Columns - max_width)
259+
#endif
260+
))
261+
{
262+
/* align right pum edge with "col" */
263+
#ifdef FEAT_RIGHTLEFT
264+
if (curwin->w_p_rl)
265+
{
266+
pum_col = col + max_width + pum_scrollbar + 1;
267+
if (pum_col >= Columns)
268+
pum_col = Columns - 1;
269+
}
270+
else
271+
#endif
272+
{
273+
pum_col = col - max_width - pum_scrollbar;
274+
if (pum_col < 0)
275+
pum_col = 0;
276+
}
277+
278+
#ifdef FEAT_RIGHTLEFT
279+
if (curwin->w_p_rl)
280+
pum_width = W_ENDCOL(curwin) - pum_col - pum_scrollbar + 1;
281+
else
282+
#endif
283+
pum_width = pum_col - pum_scrollbar;
284+
285+
if (pum_width < pum_get_width())
286+
{
287+
pum_width = pum_get_width();
288+
#ifdef FEAT_RIGHTLEFT
289+
if (curwin->w_p_rl)
290+
{
291+
if (pum_width > pum_col)
292+
pum_width = pum_col;
293+
}
294+
else
295+
#endif
296+
{
297+
if (pum_width >= Columns - pum_col)
298+
pum_width = Columns - pum_col - 1;
299+
}
300+
}
301+
else if (pum_width > max_width + pum_kind_width
302+
+ pum_extra_width + 1
303+
&& pum_width > pum_get_width())
304+
{
305+
pum_width = max_width + pum_kind_width
306+
+ pum_extra_width + 1;
307+
if (pum_width < pum_get_width())
308+
pum_width = pum_get_width();
309+
}
310+
}
311+
243312
}
244313
else if (Columns < def_width)
245314
{
@@ -254,8 +323,8 @@ pum_display(
254323
}
255324
else
256325
{
257-
if (max_width > PUM_DEF_WIDTH)
258-
max_width = PUM_DEF_WIDTH; /* truncate */
326+
if (max_width > pum_get_width())
327+
max_width = pum_get_width(); /* truncate */
259328
#ifdef FEAT_RIGHTLEFT
260329
if (curwin->w_p_rl)
261330
pum_col = max_width - 1;
@@ -1005,4 +1074,5 @@ ui_may_remove_balloon(void)
10051074
ui_remove_balloon();
10061075
}
10071076
# endif
1077+
10081078
#endif

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,8 @@ static char *(features[]) =
771771

772772
static int included_patches[] =
773773
{ /* Add new patch number below this line */
774+
/**/
775+
1491,
774776
/**/
775777
1490,
776778
/**/

0 commit comments

Comments
 (0)