vim-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 vim/vim#2314)
a8f04aa275
This commit is contained in:
Jan Edmund Lazo
2019-09-10 00:42:59 -04:00
parent 34a59242a0
commit 703ed11c97
7 changed files with 90 additions and 22 deletions

View File

@@ -4529,6 +4529,13 @@ A jump table for the options with a short description can be found at |Q_op|.
global global
Determines the maximum number of items to show in the popup menu for 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. Insert mode completion. When zero as much space as available is used.
|ins-completion-menu|.
*'pumwidth'* *'pw'*
'pumwidth' 'pw' number (default 0)
global
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|. |ins-completion-menu|.
*'pumblend'* *'pb'* *'pumblend'* *'pb'*

View File

@@ -372,6 +372,7 @@ EXTERN int p_confirm; // 'confirm'
EXTERN int p_cp; // 'compatible' EXTERN int p_cp; // 'compatible'
EXTERN char_u *p_cot; // 'completeopt' EXTERN char_u *p_cot; // 'completeopt'
EXTERN long p_ph; // 'pumheight' EXTERN long p_ph; // 'pumheight'
EXTERN long p_pw; // 'pumwidth'
EXTERN long p_pb; // 'pumblend' EXTERN long p_pb; // 'pumblend'
EXTERN char_u *p_cpo; // 'cpoptions' EXTERN char_u *p_cpo; // 'cpoptions'
EXTERN char_u *p_csprg; // 'cscopeprg' EXTERN char_u *p_csprg; // 'cscopeprg'

View File

@@ -1822,6 +1822,13 @@ return {
varname='p_ph', varname='p_ph',
defaults={if_true={vi=0}} defaults={if_true={vi=0}}
}, },
{
full_name='pumwidth', abbreviation='pw',
type='number', scope={'global'},
vi_def=true,
varname='p_pw',
defaults={if_true={vi=0}}
},
{ {
full_name='pumblend', abbreviation='pb', full_name='pumblend', abbreviation='pb',
type='number', scope={'global'}, type='number', scope={'global'},

View File

@@ -82,6 +82,13 @@ static void pum_compute_size(void)
} }
} }
// Return the minimum width of the popup menu.
static int pum_get_width(void)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{
return p_pw == 0 ? PUM_DEF_WIDTH : (int)p_pw;
}
/// Show the popup menu with items "array[size]". /// Show the popup menu with items "array[size]".
/// "array" must remain valid until pum_undisplay() is called! /// "array" must remain valid until pum_undisplay() is called!
/// When possible the leftmost character is aligned with screen column "col". /// When possible the leftmost character is aligned with screen column "col".
@@ -161,7 +168,7 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed,
} }
} }
def_width = PUM_DEF_WIDTH; def_width = pum_get_width();
win_T *pvwin = NULL; win_T *pvwin = NULL;
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
@@ -277,11 +284,13 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed,
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))
&& !curwin->w_p_rl) && !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)))) {
// align pum column with "col" // align pum column with "col"
pum_col = col; pum_col = col;
// start with the maximum space available
if (curwin->w_p_rl) { if (curwin->w_p_rl) {
pum_width = pum_col - pum_scrollbar + 1; pum_width = pum_col - pum_scrollbar + 1;
} else { } else {
@@ -291,11 +300,54 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed,
} }
if ((pum_width > max_width + pum_kind_width + pum_extra_width + 1) 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; pum_width = max_width + pum_kind_width + pum_extra_width + 1;
if (pum_width < PUM_DEF_WIDTH) { if (pum_width < pum_get_width()) {
pum_width = PUM_DEF_WIDTH; pum_width = pum_get_width();
}
}
} else if (((col > pum_get_width() || col > max_width)
&& !curwin->w_p_rl)
|| (curwin->w_p_rl
&& (col < Columns - pum_get_width()
|| col < Columns - max_width))) {
// align right pum edge with "col"
if (curwin->w_p_rl) {
pum_col = col + max_width + pum_scrollbar + 1;
if (pum_col >= Columns) {
pum_col = Columns - 1;
}
} else {
pum_col = col - max_width - pum_scrollbar;
if (pum_col < 0) {
pum_col = 0;
}
}
if (curwin->w_p_rl) {
pum_width = W_ENDCOL(curwin) - pum_col - pum_scrollbar + 1;
} else {
pum_width = pum_col - pum_scrollbar;
}
if (pum_width < pum_get_width()) {
pum_width = pum_get_width();
if (curwin->w_p_rl) {
if (pum_width > pum_col) {
pum_width = pum_col;
}
} else {
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) { } else if (Columns < def_width) {
@@ -309,9 +361,9 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed,
assert(Columns - 1 >= INT_MIN); assert(Columns - 1 >= INT_MIN);
pum_width = (int)(Columns - 1); pum_width = (int)(Columns - 1);
} else { } else {
if (max_width > PUM_DEF_WIDTH) { if (max_width > pum_get_width()) {
// truncate // truncate
max_width = PUM_DEF_WIDTH; max_width = pum_get_width();
} }
if (curwin->w_p_rl) { if (curwin->w_p_rl) {

View File

@@ -121,8 +121,6 @@
#define MB_FILLER_CHAR '<' /* character used when a double-width character #define MB_FILLER_CHAR '<' /* character used when a double-width character
* doesn't fit. */ * doesn't fit. */
#define W_ENDCOL(wp) (wp->w_wincol + wp->w_width)
#define W_ENDROW(wp) (wp->w_winrow + wp->w_height)
// temporary buffer for rendering a single screenline, so it can be // temporary buffer for rendering a single screenline, so it can be

View File

@@ -56,6 +56,9 @@ extern StlClickDefinition *tab_page_click_defs;
/// Size of the tab_page_click_defs array /// Size of the tab_page_click_defs array
extern long tab_page_click_defs_size; extern long tab_page_click_defs_size;
#define W_ENDCOL(wp) (wp->w_wincol + wp->w_width)
#define W_ENDROW(wp) (wp->w_winrow + wp->w_height)
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS
# include "screen.h.generated.h" # include "screen.h.generated.h"
#endif #endif

View File

@@ -1157,7 +1157,7 @@ describe('builtin popupmenu', function()
screen:expect([[ screen:expect([[
some long prefix before the ^ | some long prefix before the ^ |
{1:~ }{n: word }| {1:~ }{n: word }|
{1:~ }{n: choice}| {1:~ }{n: choice }|
{1:~ }{n: text }| {1:~ }{n: text }|
{1:~ }{n: thing }| {1:~ }{n: thing }|
{1:~ }| {1:~ }|
@@ -1205,7 +1205,7 @@ describe('builtin popupmenu', function()
screen:expect([[ screen:expect([[
some long prefix before the text| some long prefix before the text|
{1:^~ }{n: word }| {1:^~ }{n: word }|
{1:~ }{n: choice}| {1:~ }{n: choice }|
{1:~ }{s: text }| {1:~ }{s: text }|
{1:~ }{n: thing }| {1:~ }{n: thing }|
{1:~ }| {1:~ }|
@@ -1302,7 +1302,7 @@ describe('builtin popupmenu', function()
screen:expect([[ screen:expect([[
some long prefix before the ^ | some long prefix before the ^ |
{1:~ }{n: word }| {1:~ }{n: word }|
{1:~ }{n: choice}| {1:~ }{n: choice }|
{1:~ }{n: text }| {1:~ }{n: text }|
{1:~ }{n: thing }| {1:~ }{n: thing }|
{1:~ }| {1:~ }|