From 703ed11c97256997aa0ce8aa5fe04b6e89e8e829 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Tue, 10 Sep 2019 00:42:59 -0400 Subject: 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 --- src/nvim/popupmnu.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 60 insertions(+), 8 deletions(-) (limited to 'src/nvim/popupmnu.c') 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) { -- cgit From 669d675ef3f7c7ed4c8b702f53e3a77a986bc7cb Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Tue, 10 Sep 2019 18:54:31 -0400 Subject: vim-patch:8.0.1495: having 'pumwidth' default to zero has no merit Problem: Having 'pumwidth' default to zero has no merit. Solution: Make the default 15, as the actual default value. https://github.com/vim/vim/commit/42443c7d7fecc3a2a72154bb6139b028438617c2 Includes 'pumwidth' documentation changes from 8.0.1531. Sort 'pum*' option in alphabetical order. --- src/nvim/popupmnu.c | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) (limited to 'src/nvim/popupmnu.c') diff --git a/src/nvim/popupmnu.c b/src/nvim/popupmnu.c index be585b78de..2ea55c0710 100644 --- a/src/nvim/popupmnu.c +++ b/src/nvim/popupmnu.c @@ -82,13 +82,6 @@ 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". @@ -104,7 +97,6 @@ static int pum_get_width(void) void pum_display(pumitem_T *array, int size, int selected, bool array_changed, int cmd_startcol) { - int def_width; int context_lines; int above_row; int below_row; @@ -168,7 +160,7 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, } } - def_width = pum_get_width(); + int def_width = (int)p_pw; win_T *pvwin = NULL; FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { @@ -284,9 +276,9 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, def_width = max_width; } - if ((((col < Columns - pum_get_width()) || (col < Columns - max_width)) + if ((((col < Columns - p_pw) || (col < Columns - max_width)) && !curwin->w_p_rl) - || (curwin->w_p_rl && ((col > pum_get_width()) || (col > max_width)))) { + || (curwin->w_p_rl && ((col > p_pw) || (col > max_width)))) { // align pum column with "col" pum_col = col; @@ -300,18 +292,18 @@ 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_get_width())) { + && (pum_width > p_pw)) { // the width is too much, make it narrower pum_width = max_width + pum_kind_width + pum_extra_width + 1; - if (pum_width < pum_get_width()) { - pum_width = pum_get_width(); + if (pum_width < p_pw) { + pum_width = (int)p_pw; } } - } else if (((col > pum_get_width() || col > max_width) + } else if (((col > p_pw || col > max_width) && !curwin->w_p_rl) || (curwin->w_p_rl - && (col < Columns - pum_get_width() + && (col < Columns - p_pw || col < Columns - max_width))) { // align right pum edge with "col" if (curwin->w_p_rl) { @@ -332,8 +324,8 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, pum_width = pum_col - pum_scrollbar; } - if (pum_width < pum_get_width()) { - pum_width = pum_get_width(); + if (pum_width < p_pw) { + pum_width = (int)p_pw; if (curwin->w_p_rl) { if (pum_width > pum_col) { pum_width = pum_col; @@ -344,10 +336,10 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, } } } else if (pum_width > max_width + pum_kind_width + pum_extra_width + 1 - && pum_width > pum_get_width()) { + && pum_width > p_pw) { pum_width = max_width + pum_kind_width + pum_extra_width + 1; - if (pum_width < pum_get_width()) { - pum_width = pum_get_width(); + if (pum_width < p_pw) { + pum_width = (int)p_pw; } } } else if (Columns < def_width) { @@ -361,9 +353,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_get_width()) { + if (max_width > p_pw) { // truncate - max_width = pum_get_width(); + max_width = (int)p_pw; } if (curwin->w_p_rl) { -- cgit From ac85d1f52f0d298b03f7d0e0be3f4b7ce777cae7 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Tue, 10 Sep 2019 19:12:29 -0400 Subject: vim-patch:8.1.0670: macro for popup menu width is unused Problem: Macro for popup menu width is unused. Solution: Remove it. (Hirohito Higashi) https://github.com/vim/vim/commit/3d631cb0b34b03c7bdf45ad852d3644c7cf62743 --- src/nvim/popupmnu.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/popupmnu.c') diff --git a/src/nvim/popupmnu.c b/src/nvim/popupmnu.c index 2ea55c0710..561cb846f1 100644 --- a/src/nvim/popupmnu.c +++ b/src/nvim/popupmnu.c @@ -54,7 +54,6 @@ static bool pum_invalid = false; // the screen was just cleared # include "popupmnu.c.generated.h" #endif #define PUM_DEF_HEIGHT 10 -#define PUM_DEF_WIDTH 15 static void pum_compute_size(void) { -- cgit From d56f36f46c400ead225caaef8ac2717ff1e4bfec Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Tue, 10 Sep 2019 20:47:33 -0400 Subject: vim-patch:8.0.1522: popup menu is positioned in the wrong place Problem: Popup menu is positioned in the wrong place. (Davit Samvelyan, Boris Staletic) Solution: Correct computation of the column and the conditions for that. (Hirohito Higashi, closes vim/vim#2640) https://github.com/vim/vim/commit/4287ed33ddc324d26dd05d3e19596dd74cf479d6 --- src/nvim/popupmnu.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/nvim/popupmnu.c') diff --git a/src/nvim/popupmnu.c b/src/nvim/popupmnu.c index 561cb846f1..a715129f8a 100644 --- a/src/nvim/popupmnu.c +++ b/src/nvim/popupmnu.c @@ -305,22 +305,25 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, && (col < Columns - p_pw || col < Columns - max_width))) { // align right pum edge with "col" - if (curwin->w_p_rl) { + if (curwin->w_p_rl + && col < max_width + pum_scrollbar + 1) { 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; + } else if (!curwin->w_p_rl) { + if (col > Columns - max_width - pum_scrollbar) { + 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; + pum_width = pum_col - pum_scrollbar + 1; } else { - pum_width = pum_col - pum_scrollbar; + pum_width = Columns - pum_col - pum_scrollbar; } if (pum_width < p_pw) { -- cgit From 51c9e3c4d19f26af11a86a8f736a74a5cb6f2fa2 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Tue, 10 Sep 2019 20:53:13 -0400 Subject: vim-patch:8.0.1538: popupmenu is too far left when completion is long Problem: Popupmenu is too far left when completion is long. (Linwei) Solution: Adjust column computations. (Hirohito Higashi, closes vim/vim#2661) https://github.com/vim/vim/commit/bb008dd3239c5fe3ac04501e38e4c950fa9426c8 --- src/nvim/popupmnu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/popupmnu.c') diff --git a/src/nvim/popupmnu.c b/src/nvim/popupmnu.c index a715129f8a..d53f2c2c7b 100644 --- a/src/nvim/popupmnu.c +++ b/src/nvim/popupmnu.c @@ -306,13 +306,13 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, || col < Columns - max_width))) { // align right pum edge with "col" if (curwin->w_p_rl - && col < max_width + pum_scrollbar + 1) { + && W_ENDCOL(curwin) < max_width + pum_scrollbar + 1) { pum_col = col + max_width + pum_scrollbar + 1; if (pum_col >= Columns) { pum_col = Columns - 1; } } else if (!curwin->w_p_rl) { - if (col > Columns - max_width - pum_scrollbar) { + if (curwin->w_wincol > Columns - max_width - pum_scrollbar) { pum_col = col - max_width - pum_scrollbar; if (pum_col < 0) { pum_col = 0; -- cgit From 1d3d84fe818efaf47d8f818fcc44368d144443a1 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 26 Dec 2019 13:21:35 -0500 Subject: vim-patch:8.1.0554: popup menu overlaps with preview window Problem: Popup menu overlaps with preview window. Solution: Adjust the height computation. (Hirohito Higashi, closes vim/vim#3414) https://github.com/vim/vim/commit/614ab8aa00346724bfc27980d25985d482269b75 Cherry-picked "row -> pum_win_row" rename changes from patch 8.1.0062. --- src/nvim/popupmnu.c | 45 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 25 deletions(-) (limited to 'src/nvim/popupmnu.c') diff --git a/src/nvim/popupmnu.c b/src/nvim/popupmnu.c index d53f2c2c7b..c9ff49d233 100644 --- a/src/nvim/popupmnu.c +++ b/src/nvim/popupmnu.c @@ -100,7 +100,7 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, int above_row; int below_row; int redo_count = 0; - int row; + int pum_win_row; int col; if (!pum_is_visible) { @@ -121,12 +121,12 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, // wildoptions=pum if (State == CMDLINE) { - row = ui_has(kUICmdline) ? 0 : cmdline_row; + pum_win_row = ui_has(kUICmdline) ? 0 : cmdline_row; col = cmd_startcol; pum_anchor_grid = ui_has(kUICmdline) ? -1 : DEFAULT_GRID_HANDLE; } else { // anchor position: the start of the completed word - row = curwin->w_wrow; + pum_win_row = curwin->w_wrow; if (curwin->w_p_rl) { col = curwin->w_width - curwin->w_wcol - 1; } else { @@ -136,7 +136,7 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, pum_anchor_grid = (int)curwin->w_grid.handle; if (!ui_has(kUIMultigrid)) { pum_anchor_grid = (int)default_grid.handle; - row += curwin->w_winrow; + pum_win_row += curwin->w_winrow; col += curwin->w_wincol; } } @@ -152,7 +152,8 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, ADD(item, STRING_OBJ(cstr_to_string((char *)array[i].pum_info))); ADD(arr, ARRAY_OBJ(item)); } - ui_call_popupmenu_show(arr, selected, row, col, pum_anchor_grid); + ui_call_popupmenu_show(arr, selected, pum_win_row, col, + pum_anchor_grid); } else { ui_call_popupmenu_select(selected); return; @@ -188,11 +189,11 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, pum_height = (int)p_ph; } - // Put the pum below "row" if possible. If there are few lines decide on - // where there is more room. - if (row + 2 >= below_row - pum_height - && row - above_row > (below_row - above_row) / 2) { - // pum above "row" + // Put the pum below "pum_win_row" if possible. + // If there are few lines decide on where there is more room. + if (pum_win_row + 2 >= below_row - pum_height + && pum_win_row - above_row > (below_row - above_row) / 2) { + // pum above "pum_win_row" pum_above = true; // Leave two lines of context if possible @@ -202,12 +203,12 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, context_lines = curwin->w_wrow - curwin->w_cline_row; } - if (row >= size + context_lines) { - pum_row = row - size - context_lines; + if (pum_win_row >= size + context_lines) { + pum_row = pum_win_row - size - context_lines; pum_height = size; } else { pum_row = 0; - pum_height = row - context_lines; + pum_height = pum_win_row - context_lines; } if ((p_ph > 0) && (pum_height > p_ph)) { @@ -215,7 +216,7 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, pum_height = (int)p_ph; } } else { - // pum below "row" + // pum below "pum_win_row" pum_above = false; // Leave two lines of context if possible @@ -226,7 +227,7 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, + curwin->w_cline_height - curwin->w_wrow; } - pum_row = row + context_lines; + pum_row = pum_win_row + context_lines; if (size > below_row - pum_row) { pum_height = below_row - pum_row; } else { @@ -243,16 +244,10 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, return; } - // If there is a preview window above, avoid drawing over it. - // Do keep at least 10 entries. - if (pvwin != NULL && pum_row < above_row && pum_height > 10) { - if (row - above_row < 10) { - pum_row = row - 10; - pum_height = 10; - } else { - pum_row = above_row; - pum_height = row - above_row; - } + // If there is a preview window above avoid drawing over it. + if (pvwin != NULL && pum_row < above_row && pum_height > above_row) { + pum_row = above_row; + pum_height = pum_win_row - above_row; } if (pum_external) { return; -- cgit From e80f61020adfe6f2503c59cfea86f47fc6b0887d Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sat, 28 Dec 2019 00:46:40 -0500 Subject: vim-patch:8.0.1540: popup menu positioning fails with longer string Problem: Popup menu positioning fails with longer string. Solution: Only align with right side of window when width is less than 'pumwidth' (closes vim/vim#2661) https://github.com/vim/vim/commit/2b10bcbfc1c025bf7e6358326ee70105e7d30e96 --- src/nvim/popupmnu.c | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) (limited to 'src/nvim/popupmnu.c') diff --git a/src/nvim/popupmnu.c b/src/nvim/popupmnu.c index c9ff49d233..4ba2a1032d 100644 --- a/src/nvim/popupmnu.c +++ b/src/nvim/popupmnu.c @@ -83,7 +83,7 @@ static void pum_compute_size(void) /// 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". +/// When possible the leftmost character is aligned with cursor column. /// The menu appears above the screen line "row" or at "row" + "height" - 1. /// /// @param array @@ -101,7 +101,7 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, int below_row; int redo_count = 0; int pum_win_row; - int col; + int cursor_col; if (!pum_is_visible) { // To keep the code simple, we only allow changing the @@ -122,22 +122,22 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, // wildoptions=pum if (State == CMDLINE) { pum_win_row = ui_has(kUICmdline) ? 0 : cmdline_row; - col = cmd_startcol; + cursor_col = cmd_startcol; pum_anchor_grid = ui_has(kUICmdline) ? -1 : DEFAULT_GRID_HANDLE; } else { // anchor position: the start of the completed word pum_win_row = curwin->w_wrow; if (curwin->w_p_rl) { - col = curwin->w_width - curwin->w_wcol - 1; + cursor_col = curwin->w_width - curwin->w_wcol - 1; } else { - col = curwin->w_wcol; + cursor_col = curwin->w_wcol; } pum_anchor_grid = (int)curwin->w_grid.handle; if (!ui_has(kUIMultigrid)) { pum_anchor_grid = (int)default_grid.handle; pum_win_row += curwin->w_winrow; - col += curwin->w_wincol; + cursor_col += curwin->w_wincol; } } @@ -152,7 +152,7 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, ADD(item, STRING_OBJ(cstr_to_string((char *)array[i].pum_info))); ADD(arr, ARRAY_OBJ(item)); } - ui_call_popupmenu_show(arr, selected, pum_win_row, col, + ui_call_popupmenu_show(arr, selected, pum_win_row, cursor_col, pum_anchor_grid); } else { ui_call_popupmenu_select(selected); @@ -270,11 +270,13 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, def_width = max_width; } - if ((((col < Columns - p_pw) || (col < Columns - max_width)) + if ((((cursor_col < Columns - p_pw) + || (cursor_col < Columns - max_width)) && !curwin->w_p_rl) - || (curwin->w_p_rl && ((col > p_pw) || (col > max_width)))) { - // align pum column with "col" - pum_col = col; + || (curwin->w_p_rl + && ((cursor_col > p_pw) || (cursor_col > max_width)))) { + // align pum with "cursor_col" + pum_col = cursor_col; // start with the maximum space available if (curwin->w_p_rl) { @@ -287,28 +289,31 @@ 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 > p_pw)) { - // the width is too much, make it narrower + // the width is more than needed for the items, make it + // narrower pum_width = max_width + pum_kind_width + pum_extra_width + 1; if (pum_width < p_pw) { pum_width = (int)p_pw; } } - } else if (((col > p_pw || col > max_width) + } else if (((cursor_col > p_pw || cursor_col > max_width) && !curwin->w_p_rl) || (curwin->w_p_rl - && (col < Columns - p_pw - || col < Columns - max_width))) { - // align right pum edge with "col" + && (cursor_col < Columns - p_pw + || cursor_col < Columns - max_width))) { + // align pum edge with "cursor_col" if (curwin->w_p_rl && W_ENDCOL(curwin) < max_width + pum_scrollbar + 1) { - pum_col = col + max_width + pum_scrollbar + 1; + pum_col = cursor_col + max_width + pum_scrollbar + 1; if (pum_col >= Columns) { pum_col = Columns - 1; } } else if (!curwin->w_p_rl) { - if (curwin->w_wincol > Columns - max_width - pum_scrollbar) { - pum_col = col - max_width - pum_scrollbar; + if (curwin->w_wincol > Columns - max_width - pum_scrollbar + && max_width <= p_pw) { + // use full width to end of the screen + pum_col = cursor_col - max_width - pum_scrollbar; if (pum_col < 0) { pum_col = 0; } @@ -515,7 +520,7 @@ void pum_redraw(void) if (size < pum_width) { // Most left character requires 2-cells but only 1 cell - // is available on screen. Put a '<' on the left of the + // is available on screen. Put a '<' on the left of the // pum item *(--rt) = '<'; size++; -- cgit From 4dabbc19d43f5832b2941bcac832f93e25534264 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Mon, 23 Mar 2020 18:53:40 +0100 Subject: popupmenu: don't use 'rightleft' option in cmdline mode Cmdline is always drawn from the left to right, so using rightleft popupmenu is not useful here --- src/nvim/popupmnu.c | 52 +++++++++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 27 deletions(-) (limited to 'src/nvim/popupmnu.c') diff --git a/src/nvim/popupmnu.c b/src/nvim/popupmnu.c index 4ba2a1032d..da34d85c00 100644 --- a/src/nvim/popupmnu.c +++ b/src/nvim/popupmnu.c @@ -38,7 +38,8 @@ static int pum_width; // width of displayed pum items static int pum_base_width; // width of pum items base static int pum_kind_width; // width of pum items kind column static int pum_extra_width; // width of extra stuff -static int pum_scrollbar; // TRUE when scrollbar present +static int pum_scrollbar; // one when scrollbar present, else zero +static bool pum_rl; // true when popupmenu is drawn 'rightleft' static int pum_anchor_grid; // grid where position is defined static int pum_row; // top row of pum @@ -110,6 +111,8 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, || (State == CMDLINE && ui_has(kUIWildmenu)); } + pum_rl = (curwin->w_p_rl && State != CMDLINE); + do { // Mark the pum as visible already here, // to avoid that must_redraw is set when 'cursorcolumn' is on. @@ -127,7 +130,7 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, } else { // anchor position: the start of the completed word pum_win_row = curwin->w_wrow; - if (curwin->w_p_rl) { + if (pum_rl) { cursor_col = curwin->w_width - curwin->w_wcol - 1; } else { cursor_col = curwin->w_wcol; @@ -270,16 +273,14 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, def_width = max_width; } - if ((((cursor_col < Columns - p_pw) - || (cursor_col < Columns - max_width)) - && !curwin->w_p_rl) - || (curwin->w_p_rl - && ((cursor_col > p_pw) || (cursor_col > max_width)))) { + if ((((cursor_col < Columns - p_pw) || (cursor_col < Columns - max_width)) + && !pum_rl) + || (pum_rl && ((cursor_col > p_pw) || (cursor_col > max_width)))) { // align pum with "cursor_col" pum_col = cursor_col; // start with the maximum space available - if (curwin->w_p_rl) { + if (pum_rl) { pum_width = pum_col - pum_scrollbar + 1; } else { assert(Columns - pum_col - pum_scrollbar >= INT_MIN @@ -297,19 +298,16 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, pum_width = (int)p_pw; } } - } else if (((cursor_col > p_pw || cursor_col > max_width) - && !curwin->w_p_rl) - || (curwin->w_p_rl - && (cursor_col < Columns - p_pw - || cursor_col < Columns - max_width))) { + } else if (((cursor_col > p_pw || cursor_col > max_width) && !pum_rl) + || (pum_rl && (cursor_col < Columns - p_pw + || cursor_col < Columns - max_width))) { // align pum edge with "cursor_col" - if (curwin->w_p_rl - && W_ENDCOL(curwin) < max_width + pum_scrollbar + 1) { + if (pum_rl && W_ENDCOL(curwin) < max_width + pum_scrollbar + 1) { pum_col = cursor_col + max_width + pum_scrollbar + 1; if (pum_col >= Columns) { pum_col = Columns - 1; } - } else if (!curwin->w_p_rl) { + } else if (!pum_rl) { if (curwin->w_wincol > Columns - max_width - pum_scrollbar && max_width <= p_pw) { // use full width to end of the screen @@ -320,7 +318,7 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, } } - if (curwin->w_p_rl) { + if (pum_rl) { pum_width = pum_col - pum_scrollbar + 1; } else { pum_width = Columns - pum_col - pum_scrollbar; @@ -328,7 +326,7 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, if (pum_width < p_pw) { pum_width = (int)p_pw; - if (curwin->w_p_rl) { + if (pum_rl) { if (pum_width > pum_col) { pum_width = pum_col; } @@ -346,7 +344,7 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, } } else if (Columns < def_width) { // not enough room, will use what we have - if (curwin->w_p_rl) { + if (pum_rl) { assert(Columns - 1 >= INT_MIN); pum_col = (int)(Columns - 1); } else { @@ -360,7 +358,7 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, max_width = (int)p_pw; } - if (curwin->w_p_rl) { + if (pum_rl) { pum_col = max_width - 1; } else { assert(Columns - max_width >= INT_MIN @@ -399,7 +397,7 @@ void pum_redraw(void) int grid_width = pum_width; int col_off = 0; bool extra_space = false; - if (curwin->w_p_rl) { + if (pum_rl) { col_off = pum_width; if (pum_col < curwin->w_wincol + curwin->w_width - 1) { grid_width += 1; @@ -460,7 +458,7 @@ void pum_redraw(void) // prepend a space if there is room if (extra_space) { - if (curwin->w_p_rl) { + if (pum_rl) { grid_putchar(&pum_grid, ' ', row, col_off + 1, attr); } else { grid_putchar(&pum_grid, ' ', row, col_off - 1, attr); @@ -507,7 +505,7 @@ void pum_redraw(void) st = (char_u *)transstr((const char *)s); *p = saved; - if (curwin->w_p_rl) { + if (pum_rl) { char_u *rt = reverse_text(st); char_u *rt_start = rt; int size = vim_strsize(rt); @@ -542,7 +540,7 @@ void pum_redraw(void) } // Display two spaces for a Tab. - if (curwin->w_p_rl) { + if (pum_rl) { grid_puts_len(&pum_grid, (char_u *)" ", 2, row, col - 1, attr); col -= 2; @@ -577,7 +575,7 @@ void pum_redraw(void) break; } - if (curwin->w_p_rl) { + if (pum_rl) { grid_fill(&pum_grid, row, row + 1, col_off - pum_base_width - n + 1, col + 1, ' ', ' ', attr); col = col_off - pum_base_width - n + 1; @@ -589,7 +587,7 @@ void pum_redraw(void) totwidth = pum_base_width + n; } - if (curwin->w_p_rl) { + if (pum_rl) { grid_fill(&pum_grid, row, row + 1, col_off - pum_width + 1, col + 1, ' ', ' ', attr); } else { @@ -598,7 +596,7 @@ void pum_redraw(void) } if (pum_scrollbar > 0) { - if (curwin->w_p_rl) { + if (pum_rl) { grid_putchar(&pum_grid, ' ', row, col_off - pum_width, i >= thumb_pos && i < thumb_pos + thumb_heigth ? attr_thumb : attr_scroll); -- cgit From 630ec6cfb8670607ddfc67dd4e56e98c17746ca6 Mon Sep 17 00:00:00 2001 From: Yatao Li Date: Mon, 24 Feb 2020 16:40:58 +0800 Subject: API/UI: Allow UI to set PUM position and size, and pass the position to CompleteChanged --- src/nvim/popupmnu.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/nvim/popupmnu.c') diff --git a/src/nvim/popupmnu.c b/src/nvim/popupmnu.c index da34d85c00..9568f319b4 100644 --- a/src/nvim/popupmnu.c +++ b/src/nvim/popupmnu.c @@ -908,10 +908,18 @@ void pum_set_event_info(dict_T *dict) if (!pum_visible()) { return; } - tv_dict_add_nr(dict, S_LEN("height"), pum_height); - tv_dict_add_nr(dict, S_LEN("width"), pum_width); - tv_dict_add_nr(dict, S_LEN("row"), pum_row); - tv_dict_add_nr(dict, S_LEN("col"), pum_col); + int w,h,r,c; + if (!ui_pum_get_pos(&w, &h, &r, &c)){ + tv_dict_add_nr(dict, S_LEN("height"), pum_height); + tv_dict_add_nr(dict, S_LEN("width"), pum_width); + tv_dict_add_nr(dict, S_LEN("row"), pum_row); + tv_dict_add_nr(dict, S_LEN("col"), pum_col); + } else { + tv_dict_add_nr(dict, S_LEN("height"), h); + tv_dict_add_nr(dict, S_LEN("width"), w); + tv_dict_add_nr(dict, S_LEN("row"), r); + tv_dict_add_nr(dict, S_LEN("col"), c); + } tv_dict_add_nr(dict, S_LEN("size"), pum_size); tv_dict_add_special(dict, S_LEN("scrollbar"), pum_scrollbar ? kSpecialVarTrue : kSpecialVarFalse); -- cgit From 9c85caa390ccf6295233c4201a60ccfa66417816 Mon Sep 17 00:00:00 2001 From: Yatao Li Date: Tue, 3 Mar 2020 17:43:02 +0800 Subject: ui_pum_get_pos: return internal pum position if external pum pos not found --- src/nvim/popupmnu.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'src/nvim/popupmnu.c') diff --git a/src/nvim/popupmnu.c b/src/nvim/popupmnu.c index 9568f319b4..5f636ba847 100644 --- a/src/nvim/popupmnu.c +++ b/src/nvim/popupmnu.c @@ -902,6 +902,18 @@ int pum_get_height(void) return pum_height; } +/// Gets the internal pum geometry. +/// +/// @return the internal pum geometry. Ignores UI external pum geometry. +/// Only valid when pum_visible() returns TRUE! +void pum_get_internal_pos(int* pwidth, int* pheight, int* prow, int* pcol) +{ + *pwidth = pum_width; + *pheight = pum_height; + *prow = pum_row; + *pcol = pum_col; +} + /// Add size information about the pum to "dict". void pum_set_event_info(dict_T *dict) { @@ -909,17 +921,11 @@ void pum_set_event_info(dict_T *dict) return; } int w,h,r,c; - if (!ui_pum_get_pos(&w, &h, &r, &c)){ - tv_dict_add_nr(dict, S_LEN("height"), pum_height); - tv_dict_add_nr(dict, S_LEN("width"), pum_width); - tv_dict_add_nr(dict, S_LEN("row"), pum_row); - tv_dict_add_nr(dict, S_LEN("col"), pum_col); - } else { - tv_dict_add_nr(dict, S_LEN("height"), h); - tv_dict_add_nr(dict, S_LEN("width"), w); - tv_dict_add_nr(dict, S_LEN("row"), r); - tv_dict_add_nr(dict, S_LEN("col"), c); - } + ui_pum_get_pos(&w, &h, &r, &c); + tv_dict_add_nr(dict, S_LEN("height"), h); + tv_dict_add_nr(dict, S_LEN("width"), w); + tv_dict_add_nr(dict, S_LEN("row"), r); + tv_dict_add_nr(dict, S_LEN("col"), c); tv_dict_add_nr(dict, S_LEN("size"), pum_size); tv_dict_add_special(dict, S_LEN("scrollbar"), pum_scrollbar ? kSpecialVarTrue : kSpecialVarFalse); -- cgit From 6da16ac931eec7be2487ee98e7f605fa12b0171d Mon Sep 17 00:00:00 2001 From: Yatao Li Date: Tue, 3 Mar 2020 18:17:37 +0800 Subject: external pum: use floating point geometry; typval: add tv_dict_add_float --- src/nvim/popupmnu.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/nvim/popupmnu.c') diff --git a/src/nvim/popupmnu.c b/src/nvim/popupmnu.c index 5f636ba847..051cd660db 100644 --- a/src/nvim/popupmnu.c +++ b/src/nvim/popupmnu.c @@ -906,7 +906,7 @@ int pum_get_height(void) /// /// @return the internal pum geometry. Ignores UI external pum geometry. /// Only valid when pum_visible() returns TRUE! -void pum_get_internal_pos(int* pwidth, int* pheight, int* prow, int* pcol) +void pum_get_internal_pos(int *pwidth, int *pheight, int *prow, int *pcol) { *pwidth = pum_width; *pheight = pum_height; @@ -920,12 +920,12 @@ void pum_set_event_info(dict_T *dict) if (!pum_visible()) { return; } - int w,h,r,c; + double w, h, r, c; ui_pum_get_pos(&w, &h, &r, &c); - tv_dict_add_nr(dict, S_LEN("height"), h); - tv_dict_add_nr(dict, S_LEN("width"), w); - tv_dict_add_nr(dict, S_LEN("row"), r); - tv_dict_add_nr(dict, S_LEN("col"), c); + tv_dict_add_float(dict, S_LEN("height"), h); + tv_dict_add_float(dict, S_LEN("width"), w); + tv_dict_add_float(dict, S_LEN("row"), r); + tv_dict_add_float(dict, S_LEN("col"), c); tv_dict_add_nr(dict, S_LEN("size"), pum_size); tv_dict_add_special(dict, S_LEN("scrollbar"), pum_scrollbar ? kSpecialVarTrue : kSpecialVarFalse); -- cgit From e34684b2ad02e759dec39c0f0958c7882120ecdc Mon Sep 17 00:00:00 2001 From: Yatao Li Date: Sun, 22 Mar 2020 17:53:45 +0800 Subject: api/ui: simplify popup menu position get/set logic; fix test --- src/nvim/popupmnu.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'src/nvim/popupmnu.c') diff --git a/src/nvim/popupmnu.c b/src/nvim/popupmnu.c index 051cd660db..532bf68190 100644 --- a/src/nvim/popupmnu.c +++ b/src/nvim/popupmnu.c @@ -902,18 +902,6 @@ int pum_get_height(void) return pum_height; } -/// Gets the internal pum geometry. -/// -/// @return the internal pum geometry. Ignores UI external pum geometry. -/// Only valid when pum_visible() returns TRUE! -void pum_get_internal_pos(int *pwidth, int *pheight, int *prow, int *pcol) -{ - *pwidth = pum_width; - *pheight = pum_height; - *prow = pum_row; - *pcol = pum_col; -} - /// Add size information about the pum to "dict". void pum_set_event_info(dict_T *dict) { @@ -921,7 +909,12 @@ void pum_set_event_info(dict_T *dict) return; } double w, h, r, c; - ui_pum_get_pos(&w, &h, &r, &c); + if (!ui_pum_get_pos(&w, &h, &r, &c)) { + w = (double)pum_width; + h = (double)pum_height; + r = (double)pum_row; + c = (double)pum_col; + } tv_dict_add_float(dict, S_LEN("height"), h); tv_dict_add_float(dict, S_LEN("width"), w); tv_dict_add_float(dict, S_LEN("row"), r); -- cgit From bc29283f209db7a7de3c999af2780c3d5a30ebae Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sat, 2 May 2020 16:23:30 -0400 Subject: vim-patch:8.2.0678: rare crash for popup menu Problem: Rare crash for popup menu. Solution: Check for NULL pointer. (Nobuhiro Takasaki, closes vim/vim#6027) https://github.com/vim/vim/commit/d58a662f44dc11475f4cf5922a948635da934cc4 --- src/nvim/popupmnu.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/nvim/popupmnu.c') diff --git a/src/nvim/popupmnu.c b/src/nvim/popupmnu.c index 532bf68190..e06433892d 100644 --- a/src/nvim/popupmnu.c +++ b/src/nvim/popupmnu.c @@ -63,9 +63,12 @@ static void pum_compute_size(void) pum_kind_width = 0; pum_extra_width = 0; for (int i = 0; i < pum_size; i++) { - int w = vim_strsize(pum_array[i].pum_text); - if (pum_base_width < w) { - pum_base_width = w; + int w; + if (pum_array[i].pum_text != NULL) { + w = vim_strsize(pum_array[i].pum_text); + if (pum_base_width < w) { + pum_base_width = w; + } } if (pum_array[i].pum_kind != NULL) { w = vim_strsize(pum_array[i].pum_kind) + 1; -- cgit From 1805fb469a39d998f9bef0415999aa835d051044 Mon Sep 17 00:00:00 2001 From: Billy Su Date: Tue, 28 Apr 2020 23:21:50 +0800 Subject: vim-patch:8.2.0111: VAR_SPECIAL is also used for booleans Problem: VAR_SPECIAL is also used for booleans. Solution: Add VAR_BOOL for better type checking. https://github.com/vim/vim/commit/9b4a15d5dba354d2e1e02871470bad103f34769a --- src/nvim/popupmnu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/popupmnu.c') diff --git a/src/nvim/popupmnu.c b/src/nvim/popupmnu.c index e06433892d..c712762bdf 100644 --- a/src/nvim/popupmnu.c +++ b/src/nvim/popupmnu.c @@ -923,6 +923,6 @@ void pum_set_event_info(dict_T *dict) tv_dict_add_float(dict, S_LEN("row"), r); tv_dict_add_float(dict, S_LEN("col"), c); tv_dict_add_nr(dict, S_LEN("size"), pum_size); - tv_dict_add_special(dict, S_LEN("scrollbar"), - pum_scrollbar ? kSpecialVarTrue : kSpecialVarFalse); + tv_dict_add_bool(dict, S_LEN("scrollbar"), + pum_scrollbar ? kBoolVarTrue : kBoolVarFalse); } -- cgit