mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
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:
parent
34a59242a0
commit
703ed11c97
@ -4529,6 +4529,13 @@ A jump table for the options with a short description can be found at |Q_op|.
|
||||
global
|
||||
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
|
||||
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|.
|
||||
|
||||
*'pumblend'* *'pb'*
|
||||
|
@ -372,6 +372,7 @@ EXTERN int p_confirm; // 'confirm'
|
||||
EXTERN int p_cp; // 'compatible'
|
||||
EXTERN char_u *p_cot; // 'completeopt'
|
||||
EXTERN long p_ph; // 'pumheight'
|
||||
EXTERN long p_pw; // 'pumwidth'
|
||||
EXTERN long p_pb; // 'pumblend'
|
||||
EXTERN char_u *p_cpo; // 'cpoptions'
|
||||
EXTERN char_u *p_csprg; // 'cscopeprg'
|
||||
|
@ -1822,6 +1822,13 @@ return {
|
||||
varname='p_ph',
|
||||
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',
|
||||
type='number', scope={'global'},
|
||||
|
@ -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]".
|
||||
/// "array" must remain valid until pum_undisplay() is called!
|
||||
/// 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;
|
||||
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;
|
||||
}
|
||||
|
||||
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 && ((col > PUM_DEF_WIDTH) || (col > max_width)))) {
|
||||
|| (curwin->w_p_rl && ((col > pum_get_width()) || (col > max_width)))) {
|
||||
// align pum column with "col"
|
||||
pum_col = col;
|
||||
|
||||
// start with the maximum space available
|
||||
if (curwin->w_p_rl) {
|
||||
pum_width = pum_col - pum_scrollbar + 1;
|
||||
} 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)
|
||||
&& (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)
|
||||
&& !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) {
|
||||
@ -309,9 +361,9 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed,
|
||||
assert(Columns - 1 >= INT_MIN);
|
||||
pum_width = (int)(Columns - 1);
|
||||
} else {
|
||||
if (max_width > PUM_DEF_WIDTH) {
|
||||
if (max_width > pum_get_width()) {
|
||||
// truncate
|
||||
max_width = PUM_DEF_WIDTH;
|
||||
max_width = pum_get_width();
|
||||
}
|
||||
|
||||
if (curwin->w_p_rl) {
|
||||
|
@ -121,8 +121,6 @@
|
||||
|
||||
#define MB_FILLER_CHAR '<' /* character used when a double-width character
|
||||
* 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
|
||||
|
@ -56,6 +56,9 @@ extern StlClickDefinition *tab_page_click_defs;
|
||||
/// Size of the tab_page_click_defs array
|
||||
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
|
||||
# include "screen.h.generated.h"
|
||||
#endif
|
||||
|
@ -1156,10 +1156,10 @@ describe('builtin popupmenu', function()
|
||||
funcs.complete(29, {'word', 'choice', 'text', 'thing'})
|
||||
screen:expect([[
|
||||
some long prefix before the ^ |
|
||||
{1:~ }{n: word }|
|
||||
{1:~ }{n: choice}|
|
||||
{1:~ }{n: text }|
|
||||
{1:~ }{n: thing }|
|
||||
{1:~ }{n: word }|
|
||||
{1:~ }{n: choice }|
|
||||
{1:~ }{n: text }|
|
||||
{1:~ }{n: thing }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
@ -1204,10 +1204,10 @@ describe('builtin popupmenu', function()
|
||||
feed('<c-p>')
|
||||
screen:expect([[
|
||||
some long prefix before the text|
|
||||
{1:^~ }{n: word }|
|
||||
{1:~ }{n: choice}|
|
||||
{1:~ }{s: text }|
|
||||
{1:~ }{n: thing }|
|
||||
{1:^~ }{n: word }|
|
||||
{1:~ }{n: choice }|
|
||||
{1:~ }{s: text }|
|
||||
{1:~ }{n: thing }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
@ -1301,10 +1301,10 @@ describe('builtin popupmenu', function()
|
||||
funcs.complete(29, {'word', 'choice', 'text', 'thing'})
|
||||
screen:expect([[
|
||||
some long prefix before the ^ |
|
||||
{1:~ }{n: word }|
|
||||
{1:~ }{n: choice}|
|
||||
{1:~ }{n: text }|
|
||||
{1:~ }{n: thing }|
|
||||
{1:~ }{n: word }|
|
||||
{1:~ }{n: choice }|
|
||||
{1:~ }{n: text }|
|
||||
{1:~ }{n: thing }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
|
Loading…
Reference in New Issue
Block a user