diff options
author | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2019-09-10 00:42:59 -0400 |
---|---|---|
committer | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2019-12-29 18:15:46 -0500 |
commit | 703ed11c97256997aa0ce8aa5fe04b6e89e8e829 (patch) | |
tree | 402cdbb43de7fd560947b73ff294a6ad03cdfbe1 /src/nvim/popupmnu.c | |
parent | 34a59242a0d42687a49119cca590e7b4203496ef (diff) | |
download | rneovim-703ed11c97256997aa0ce8aa5fe04b6e89e8e829.tar.gz rneovim-703ed11c97256997aa0ce8aa5fe04b6e89e8e829.tar.bz2 rneovim-703ed11c97256997aa0ce8aa5fe04b6e89e8e829.zip |
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)
https://github.com/vim/vim/commit/a8f04aa275984183bab5bb583b128f38c64abb69
Diffstat (limited to 'src/nvim/popupmnu.c')
-rw-r--r-- | src/nvim/popupmnu.c | 68 |
1 files changed, 60 insertions, 8 deletions
diff --git a/src/nvim/popupmnu.c b/src/nvim/popupmnu.c index 7a7f8a9d75..be585b78de 100644 --- a/src/nvim/popupmnu.c +++ b/src/nvim/popupmnu.c @@ -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) { |