From 2bed0d1d978b42184564201088ea5fef12ec8581 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 22 Aug 2022 13:56:50 +0800 Subject: vim-patch:8.2.4753: error from setting an option is silently ignored (#19888) Problem: Error from setting an option is silently ignored. Solution: Handle option value errors better. Fix uses of N_(). https://github.com/vim/vim/commit/31e5c60a682840959cae6273ccadd9aae48c928d --- src/nvim/popupmenu.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/popupmenu.c') diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c index a4afe97ac8..d392bb5a2c 100644 --- a/src/nvim/popupmenu.c +++ b/src/nvim/popupmenu.c @@ -744,11 +744,11 @@ static bool pum_set_selected(int n, int repeat) if (res == OK) { // Edit a new, empty buffer. Set options for a "wipeout" // buffer. - set_option_value("swf", 0L, NULL, OPT_LOCAL); - set_option_value("bl", 0L, NULL, OPT_LOCAL); - set_option_value("bt", 0L, "nofile", OPT_LOCAL); - set_option_value("bh", 0L, "wipe", OPT_LOCAL); - set_option_value("diff", 0L, NULL, OPT_LOCAL); + set_option_value_give_err("swf", 0L, NULL, OPT_LOCAL); + set_option_value_give_err("bl", 0L, NULL, OPT_LOCAL); + set_option_value_give_err("bt", 0L, "nofile", OPT_LOCAL); + set_option_value_give_err("bh", 0L, "wipe", OPT_LOCAL); + set_option_value_give_err("diff", 0L, NULL, OPT_LOCAL); } } -- cgit From 6cc6e11929ad76a2dc5204aed95cb9ed1dafde23 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 23 Aug 2022 22:00:19 +0800 Subject: vim-patch:9.0.0206: redraw flags are not named specifically (#19913) Problem: Redraw flags are not named specifically. Solution: Prefix "UPD_" to the flags, for UPDate_screen(). https://github.com/vim/vim/commit/a4d158b3c839e96ed98ff87c7b7124ff4518c4ff --- src/nvim/popupmenu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/popupmenu.c') diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c index d392bb5a2c..2eaf0a17fb 100644 --- a/src/nvim/popupmenu.c +++ b/src/nvim/popupmenu.c @@ -802,7 +802,7 @@ static bool pum_set_selected(int n, int repeat) // Return cursor to where we were validate_cursor(); - redraw_later(curwin, SOME_VALID); + redraw_later(curwin, UPD_SOME_VALID); // When the preview window was resized we need to // update the view on the buffer. Only go back to -- cgit From bcf5ee328e228d5a536b4de2069a79234f9f3e9e Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 23 Aug 2022 10:36:46 +0200 Subject: refactor(arena): use a shared block freelist This is both simpler in client code and more effective (always reuse block hottest in cache) --- src/nvim/popupmenu.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/nvim/popupmenu.c') diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c index d392bb5a2c..f570556a29 100644 --- a/src/nvim/popupmenu.c +++ b/src/nvim/popupmenu.c @@ -156,7 +156,6 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, i if (pum_external) { if (array_changed) { Arena arena = ARENA_EMPTY; - arena_start(&arena, &ui_ext_fixblk); Array arr = arena_array(&arena, (size_t)size); for (int i = 0; i < size; i++) { Array item = arena_array(&arena, 4); @@ -168,7 +167,7 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, i } ui_call_popupmenu_show(arr, selected, pum_win_row, cursor_col, pum_anchor_grid); - arena_mem_free(arena_finish(&arena), &ui_ext_fixblk); + arena_mem_free(arena_finish(&arena)); } else { ui_call_popupmenu_select(selected); return; -- cgit From 395277036014189c03b8969fc0a5cd2bdc5c8631 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 10:36:35 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/popupmenu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/popupmenu.c') diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c index 1f36e25433..529e351f33 100644 --- a/src/nvim/popupmenu.c +++ b/src/nvim/popupmenu.c @@ -703,7 +703,7 @@ static bool pum_set_selected(int n, int repeat) if ((pum_array[pum_selected].pum_info != NULL) && (Rows > 10) && (repeat <= 1) - && (vim_strchr((char *)p_cot, 'p') != NULL)) { + && (vim_strchr(p_cot, 'p') != NULL)) { win_T *curwin_save = curwin; tabpage_T *curtab_save = curtab; int res = OK; -- cgit From 58f30a326f34319801e7921f32c83e8320d85f6c Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/popupmenu.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/nvim/popupmenu.c') diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c index 529e351f33..b144348188 100644 --- a/src/nvim/popupmenu.c +++ b/src/nvim/popupmenu.c @@ -542,14 +542,13 @@ void pum_redraw(void) size++; } } - grid_puts_len(&pum_grid, (char_u *)rt, (int)STRLEN(rt), row, - grid_col - size + 1, attr); + grid_puts_len(&pum_grid, rt, (int)STRLEN(rt), row, grid_col - size + 1, attr); xfree(rt_start); xfree(st); grid_col -= width; } else { // use grid_puts_len() to truncate the text - grid_puts(&pum_grid, st, row, grid_col, attr); + grid_puts(&pum_grid, (char *)st, row, grid_col, attr); xfree(st); grid_col += width; } @@ -560,11 +559,11 @@ void pum_redraw(void) // Display two spaces for a Tab. if (pum_rl) { - grid_puts_len(&pum_grid, (char_u *)" ", 2, row, grid_col - 1, + grid_puts_len(&pum_grid, " ", 2, row, grid_col - 1, attr); grid_col -= 2; } else { - grid_puts_len(&pum_grid, (char_u *)" ", 2, row, grid_col, attr); + grid_puts_len(&pum_grid, " ", 2, row, grid_col, attr); grid_col += 2; } totwidth += 2; -- cgit From 2828aae7b49921380f229ebf4d7432f39c6c2c2b Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 30 Aug 2022 14:52:09 +0200 Subject: refactor: replace char_u with char 4 (#19987) * refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/popupmenu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/popupmenu.c') diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c index b144348188..0d9080ceb7 100644 --- a/src/nvim/popupmenu.c +++ b/src/nvim/popupmenu.c @@ -524,7 +524,7 @@ void pum_redraw(void) } if (pum_rl) { - char *rt = (char *)reverse_text(st); + char *rt = reverse_text((char *)st); char *rt_start = rt; int size = vim_strsize(rt); -- cgit From 82d128405aaeb619a0c04353449f5717da126249 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 24 Jul 2022 15:24:15 +0800 Subject: feat(pum): pretend 'mousemoveevent' is set when showing right-click menu --- src/nvim/popupmenu.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/nvim/popupmenu.c') diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c index 0d9080ceb7..2265334a45 100644 --- a/src/nvim/popupmenu.c +++ b/src/nvim/popupmenu.c @@ -1042,6 +1042,10 @@ void pum_show_popupmenu(vimmenu_T *menu) pum_scrollbar = 0; pum_height = pum_size; pum_position_at_mouse(20); + if (!p_mousemev) { + // Pretend 'mousemoveevent' is set. + ui_call_option_set(STATIC_CSTR_AS_STRING("mousemoveevent"), BOOLEAN_OBJ(true)); + } pum_selected = -1; pum_first = 0; @@ -1102,6 +1106,9 @@ void pum_show_popupmenu(vimmenu_T *menu) xfree(array); pum_undisplay(true); + if (!p_mousemev) { + ui_call_option_set(STATIC_CSTR_AS_STRING("mousemoveevent"), BOOLEAN_OBJ(false)); + } } void pum_make_popup(const char *path_name, int use_mouse_pos) -- cgit From f6a8d395a72da61c9305cd242f38bd8137c4f5b0 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 5 Sep 2022 22:10:14 +0800 Subject: refactor(ex_cd): add an early return to fix clint warning The popupmenu.c change is unrelated. --- src/nvim/popupmenu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/popupmenu.c') diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c index 2265334a45..4de3713f4f 100644 --- a/src/nvim/popupmenu.c +++ b/src/nvim/popupmenu.c @@ -1042,14 +1042,14 @@ void pum_show_popupmenu(vimmenu_T *menu) pum_scrollbar = 0; pum_height = pum_size; pum_position_at_mouse(20); + + pum_selected = -1; + pum_first = 0; if (!p_mousemev) { // Pretend 'mousemoveevent' is set. ui_call_option_set(STATIC_CSTR_AS_STRING("mousemoveevent"), BOOLEAN_OBJ(true)); } - pum_selected = -1; - pum_first = 0; - for (;;) { pum_is_visible = true; pum_is_drawn = true; -- cgit From 3ff46544c9872b4161fd098569c30b55fe3abd36 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/popupmenu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/popupmenu.c') diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c index 4de3713f4f..5483c9cb94 100644 --- a/src/nvim/popupmenu.c +++ b/src/nvim/popupmenu.c @@ -542,7 +542,7 @@ void pum_redraw(void) size++; } } - grid_puts_len(&pum_grid, rt, (int)STRLEN(rt), row, grid_col - size + 1, attr); + grid_puts_len(&pum_grid, rt, (int)strlen(rt), row, grid_col - size + 1, attr); xfree(rt_start); xfree(st); grid_col -= width; -- cgit From 6679687bb3909f853ae97dfa01ae08ea2baf7f97 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 26 Sep 2022 15:17:10 +0200 Subject: refactor(redraw): no type argument in update_screen() This was used in the past with assumption that curwin/curbuf is "special" but this has not been true since basically forever at this point. Reduce NOT_VALID/CLEAR panic in options.lua . These should not be set if an effect of the option is causing something which by itself invokes redraw_later(). --- src/nvim/popupmenu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/popupmenu.c') diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c index 5483c9cb94..74376c8b8a 100644 --- a/src/nvim/popupmenu.c +++ b/src/nvim/popupmenu.c @@ -818,7 +818,7 @@ static bool pum_set_selected(int n, int repeat) // TODO(bfredl): can simplify, get rid of the flag munging? // or at least eliminate extra redraw before win_enter()? pum_is_visible = false; - update_screen(0); + update_screen(); pum_is_visible = true; if (!resized && win_valid(curwin_save)) { @@ -830,7 +830,7 @@ static bool pum_set_selected(int n, int repeat) // May need to update the screen again when there are // autocommands involved. pum_is_visible = false; - update_screen(0); + update_screen(); pum_is_visible = true; } } -- cgit From e6f7e038b8bbca487e78ebfc6fe21d6852330623 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 14 Oct 2022 23:08:00 +0800 Subject: fix(completion): set pum_size even if ext_popupmenu is used (#20648) This allows CompleteChanged event to get the correct `v:event.size`. It should be harmless and more consistent to also set `pum_array`. --- src/nvim/popupmenu.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/nvim/popupmenu.c') diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c index 74376c8b8a..3a3f966d10 100644 --- a/src/nvim/popupmenu.c +++ b/src/nvim/popupmenu.c @@ -264,12 +264,15 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, i pum_row = above_row; pum_height = pum_win_row - above_row; } + + pum_array = array; + // Set "pum_size" before returning so that pum_set_event_info() gets the correct size. + pum_size = size; + if (pum_external) { return; } - pum_array = array; - pum_size = size; pum_compute_size(); int max_width = pum_base_width; -- cgit From 637ab296cba9e37e7374a8c076342487398605ee Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 17 Oct 2022 21:00:50 +0800 Subject: feat(api): nvim_select_popupmenu_item support cmdline pum (#20652) --- src/nvim/popupmenu.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/nvim/popupmenu.c') diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c index 3a3f966d10..893ed38e25 100644 --- a/src/nvim/popupmenu.c +++ b/src/nvim/popupmenu.c @@ -904,6 +904,17 @@ void pum_recompose(void) ui_comp_compose_grid(&pum_grid); } +void pum_ext_select_item(int item, bool insert, bool finish) +{ + if (!pum_visible() || item < -1 || item >= pum_size) { + return; + } + pum_want.active = true; + pum_want.item = item; + pum_want.insert = insert; + pum_want.finish = finish; +} + /// Gets the height of the menu. /// /// @return the height of the popup menu, the number of entries visible. -- cgit From 731cdde28ea8d48cc23ba2752a08c261c87eee92 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 22 Oct 2022 12:36:38 +0200 Subject: refactor: fix clang-tidy warnings Enable and fix bugprone-misplaced-widening-cast warning. Fix some modernize-macro-to-enum and readability-else-after-return warnings, but don't enable them. While the warnings can be useful, they are in general too noisy to enable. --- src/nvim/popupmenu.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/nvim/popupmenu.c') diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c index 893ed38e25..db22d50d66 100644 --- a/src/nvim/popupmenu.c +++ b/src/nvim/popupmenu.c @@ -762,12 +762,11 @@ static bool pum_set_selected(int n, int repeat) if (e == NULL) { ml_append(lnum++, (char *)p, 0, false); break; - } else { - *e = NUL; - ml_append(lnum++, (char *)p, (int)(e - p + 1), false); - *e = '\n'; - p = e + 1; } + *e = NUL; + ml_append(lnum++, (char *)p, (int)(e - p + 1), false); + *e = '\n'; + p = e + 1; } // Increase the height of the preview window to show the -- cgit From 2425fe2dc5e5985779912319433ddf914a20dd6a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 12 Nov 2022 09:57:29 +0800 Subject: vim-patch:8.2.2207: illegal memory access if popup menu items are changed (#21028) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Illegal memory access if popup menu items are changed while the menu is visible. (Tomáš Janoušek) Solution: Make a copy of the text. (closes vim/vim#7537) https://github.com/vim/vim/commit/38455a921395a56690790c8c1d28c1c43ca04c8a Co-authored-by: Bram Moolenaar --- src/nvim/popupmenu.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/nvim/popupmenu.c') diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c index db22d50d66..234ce5fcba 100644 --- a/src/nvim/popupmenu.c +++ b/src/nvim/popupmenu.c @@ -1043,10 +1043,16 @@ void pum_show_popupmenu(vimmenu_T *menu) pumitem_T *array = (pumitem_T *)xcalloc((size_t)pum_size, sizeof(pumitem_T)); for (vimmenu_T *mp = menu->children; mp != NULL; mp = mp->next) { + char *s = NULL; + // Make a copy of the text, the menu may be redefined in a callback. if (menu_is_separator(mp->dname)) { - array[idx++].pum_text = (char_u *)""; + s = ""; } else if (mp->modes & mp->enabled & mode) { - array[idx++].pum_text = (char_u *)mp->dname; + s = mp->dname; + } + if (s != NULL) { + s = xstrdup(s); + array[idx++].pum_text = (char_u *)s; } } @@ -1117,6 +1123,9 @@ void pum_show_popupmenu(vimmenu_T *menu) } } + for (idx = 0; idx < pum_size; idx++) { + xfree(array[idx].pum_text); + } xfree(array); pum_undisplay(true); if (!p_mousemev) { -- cgit From 66360675cf4d091b7460e4a8e1435c13216c1929 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 11 Sep 2022 17:12:44 +0200 Subject: build: allow IWYU to fix includes for all .c files Allow Include What You Use to remove unnecessary includes and only include what is necessary. This helps with reducing compilation times and makes it easier to visualise which dependencies are actually required. Work on https://github.com/neovim/neovim/issues/549, but doesn't close it since this only works fully for .c files and not headers. --- src/nvim/popupmenu.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/nvim/popupmenu.c') diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c index 234ce5fcba..567230fab4 100644 --- a/src/nvim/popupmenu.c +++ b/src/nvim/popupmenu.c @@ -6,27 +6,35 @@ /// Popup menu (PUM) #include -#include +#include #include +#include +#include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" #include "nvim/ascii.h" #include "nvim/buffer.h" #include "nvim/charset.h" #include "nvim/drawscreen.h" -#include "nvim/edit.h" #include "nvim/eval/typval.h" +#include "nvim/eval/typval_defs.h" #include "nvim/ex_cmds.h" +#include "nvim/getchar.h" +#include "nvim/globals.h" #include "nvim/grid.h" #include "nvim/highlight.h" #include "nvim/insexpand.h" +#include "nvim/keycodes.h" +#include "nvim/mbyte.h" #include "nvim/memline.h" #include "nvim/memory.h" #include "nvim/menu.h" +#include "nvim/message.h" #include "nvim/move.h" #include "nvim/option.h" #include "nvim/popupmenu.h" -#include "nvim/search.h" +#include "nvim/pos.h" +#include "nvim/screen.h" #include "nvim/strings.h" #include "nvim/ui.h" #include "nvim/ui_compositor.h" -- cgit From b603d6f9e71f7ac1e34cfff5007834a765250922 Mon Sep 17 00:00:00 2001 From: shirasaka Date: Tue, 10 Jan 2023 23:40:27 +0900 Subject: fix: properly close builtin popup in ext_popupmenu --- src/nvim/popupmenu.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/popupmenu.c') diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c index 567230fab4..12e868f327 100644 --- a/src/nvim/popupmenu.c +++ b/src/nvim/popupmenu.c @@ -878,6 +878,7 @@ void pum_check_clear(void) grid_free(&pum_grid); } pum_is_drawn = false; + pum_external = false; } } -- cgit From f2141de9e462ed8976b2a59337c32a0fcba2a11d Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Fri, 13 Jan 2023 00:35:39 +0100 Subject: refactor: replace char_u with char 20 (#21714) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/popupmenu.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'src/nvim/popupmenu.c') diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c index 567230fab4..ba90983e37 100644 --- a/src/nvim/popupmenu.c +++ b/src/nvim/popupmenu.c @@ -408,8 +408,8 @@ void pum_redraw(void) int attr; int i; int idx; - char_u *s; - char_u *p = NULL; + char *s; + char *p = NULL; int totwidth, width, w; int thumb_pos = 0; int thumb_height = 1; @@ -501,15 +501,15 @@ void pum_redraw(void) switch (round) { case 1: - p = pum_array[idx].pum_text; + p = (char *)pum_array[idx].pum_text; break; case 2: - p = pum_array[idx].pum_kind; + p = (char *)pum_array[idx].pum_kind; break; case 3: - p = pum_array[idx].pum_extra; + p = (char *)pum_array[idx].pum_extra; break; } @@ -518,24 +518,24 @@ void pum_redraw(void) if (s == NULL) { s = p; } - w = ptr2cells((char *)p); + w = ptr2cells(p); if ((*p == NUL) || (*p == TAB) || (totwidth + w > pum_width)) { // Display the text that fits or comes before a Tab. // First convert it to printable characters. - char_u *st; - char_u saved = *p; + char *st; + char saved = *p; if (saved != NUL) { *p = NUL; } - st = (char_u *)transstr((const char *)s, true); + st = transstr(s, true); if (saved != NUL) { *p = saved; } if (pum_rl) { - char *rt = reverse_text((char *)st); + char *rt = reverse_text(st); char *rt_start = rt; int size = vim_strsize(rt); @@ -559,7 +559,7 @@ void pum_redraw(void) grid_col -= width; } else { // use grid_puts_len() to truncate the text - grid_puts(&pum_grid, (char *)st, row, grid_col, attr); + grid_puts(&pum_grid, st, row, grid_col, attr); xfree(st); grid_col += width; } @@ -762,17 +762,17 @@ static bool pum_set_selected(int n, int repeat) } if (res == OK) { - char_u *p, *e; + char *p, *e; linenr_T lnum = 0; - for (p = pum_array[pum_selected].pum_info; *p != NUL;) { - e = (char_u *)vim_strchr((char *)p, '\n'); + for (p = (char *)pum_array[pum_selected].pum_info; *p != NUL;) { + e = vim_strchr(p, '\n'); if (e == NULL) { - ml_append(lnum++, (char *)p, 0, false); + ml_append(lnum++, p, 0, false); break; } *e = NUL; - ml_append(lnum++, (char *)p, (int)(e - p + 1), false); + ml_append(lnum++, p, (int)(e - p + 1), false); *e = '\n'; p = e + 1; } -- cgit From e89c39d6f016a4140293755250e968e839009617 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 14 Jan 2023 08:58:28 +0100 Subject: refactor: replace char_u with char 21 (#21779) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/popupmenu.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/nvim/popupmenu.c') diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c index ba90983e37..1d55b2ef31 100644 --- a/src/nvim/popupmenu.c +++ b/src/nvim/popupmenu.c @@ -78,19 +78,19 @@ static void pum_compute_size(void) for (int i = 0; i < pum_size; i++) { int w; if (pum_array[i].pum_text != NULL) { - w = vim_strsize((char *)pum_array[i].pum_text); + 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((char *)pum_array[i].pum_kind) + 1; + w = vim_strsize(pum_array[i].pum_kind) + 1; if (pum_kind_width < w) { pum_kind_width = w; } } if (pum_array[i].pum_extra != NULL) { - w = vim_strsize((char *)pum_array[i].pum_extra) + 1; + w = vim_strsize(pum_array[i].pum_extra) + 1; if (pum_extra_width < w) { pum_extra_width = w; } @@ -167,10 +167,10 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, i Array arr = arena_array(&arena, (size_t)size); for (int i = 0; i < size; i++) { Array item = arena_array(&arena, 4); - ADD_C(item, STRING_OBJ(cstr_as_string((char *)array[i].pum_text))); - ADD_C(item, STRING_OBJ(cstr_as_string((char *)array[i].pum_kind))); - ADD_C(item, STRING_OBJ(cstr_as_string((char *)array[i].pum_extra))); - ADD_C(item, STRING_OBJ(cstr_as_string((char *)array[i].pum_info))); + ADD_C(item, STRING_OBJ(cstr_as_string(array[i].pum_text))); + ADD_C(item, STRING_OBJ(cstr_as_string(array[i].pum_kind))); + ADD_C(item, STRING_OBJ(cstr_as_string(array[i].pum_extra))); + ADD_C(item, STRING_OBJ(cstr_as_string(array[i].pum_info))); ADD_C(arr, ARRAY_OBJ(item)); } ui_call_popupmenu_show(arr, selected, pum_win_row, cursor_col, @@ -501,15 +501,15 @@ void pum_redraw(void) switch (round) { case 1: - p = (char *)pum_array[idx].pum_text; + p = pum_array[idx].pum_text; break; case 2: - p = (char *)pum_array[idx].pum_kind; + p = pum_array[idx].pum_kind; break; case 3: - p = (char *)pum_array[idx].pum_extra; + p = pum_array[idx].pum_extra; break; } @@ -765,7 +765,7 @@ static bool pum_set_selected(int n, int repeat) char *p, *e; linenr_T lnum = 0; - for (p = (char *)pum_array[pum_selected].pum_info; *p != NUL;) { + for (p = pum_array[pum_selected].pum_info; *p != NUL;) { e = vim_strchr(p, '\n'); if (e == NULL) { ml_append(lnum++, p, 0, false); @@ -1060,7 +1060,7 @@ void pum_show_popupmenu(vimmenu_T *menu) } if (s != NULL) { s = xstrdup(s); - array[idx++].pum_text = (char_u *)s; + array[idx++].pum_text = s; } } -- cgit From 6e3890f4ce002ba308c09166b00e8ee86b6efa03 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 19 Jan 2023 15:13:27 +0800 Subject: vim-patch:8.2.4655: cmdline completion popup menu positioned wrong (#21894) Problem: Command line completion popup menu positioned wrong when using a terminal window. Solution: Position the popup menu differently when editing the command line. (Yegappan Lakshmanan, closes vim/vim#10050, closes vim/vim#10035) https://github.com/vim/vim/commit/1104a6d0c2004d39e9b6cb8f804d12b628a69869 The test in the patch looks a bit hard to understand. Add a Lua test that is more straightforward. Co-authored-by: Yegappan Lakshmanan --- src/nvim/popupmenu.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'src/nvim/popupmenu.c') diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c index 14ee71d50a..b97a25dd0b 100644 --- a/src/nvim/popupmenu.c +++ b/src/nvim/popupmenu.c @@ -218,11 +218,16 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, i // pum above "pum_win_row" pum_above = true; - // Leave two lines of context if possible - if (curwin->w_wrow - curwin->w_cline_row >= 2) { - context_lines = 2; + if (State == MODE_CMDLINE) { + // for cmdline pum, no need for context lines + context_lines = 0; } else { - context_lines = curwin->w_wrow - curwin->w_cline_row; + // Leave two lines of context if possible + if (curwin->w_wrow - curwin->w_cline_row >= 2) { + context_lines = 2; + } else { + context_lines = curwin->w_wrow - curwin->w_cline_row; + } } if (pum_win_row >= size + context_lines) { @@ -241,13 +246,17 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, i // pum below "pum_win_row" pum_above = false; - // Leave two lines of context if possible - validate_cheight(); - if (curwin->w_cline_row + curwin->w_cline_height - curwin->w_wrow >= 3) { - context_lines = 3; + if (State == MODE_CMDLINE) { + // for cmdline pum, no need for context lines + context_lines = 0; } else { - context_lines = curwin->w_cline_row - + curwin->w_cline_height - curwin->w_wrow; + // Leave two lines of context if possible + validate_cheight(); + if (curwin->w_cline_row + curwin->w_cline_height - curwin->w_wrow >= 3) { + context_lines = 3; + } else { + context_lines = curwin->w_cline_row + curwin->w_cline_height - curwin->w_wrow; + } } pum_row = pum_win_row + context_lines; -- cgit From 0f52e2c849cbd923fc30b8bbef088b6f7642aeab Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 21 Jan 2023 20:50:46 +0800 Subject: vim-patch:8.2.0382: some tests fail when run under valgrind (#21936) Problem: Some tests fail when run under valgrind. Solution: Increase timeouts. https://github.com/vim/vim/commit/353c351bd22e4dac4c3ae9cd7731032348f248c4 Cherry-pick Test_pum_with_preview_win() from patch 8.2.0011. Co-authored-by: Bram Moolenaar --- src/nvim/popupmenu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/popupmenu.c') diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c index b97a25dd0b..245ce87865 100644 --- a/src/nvim/popupmenu.c +++ b/src/nvim/popupmenu.c @@ -824,7 +824,7 @@ static bool pum_set_selected(int n, int repeat) // When the preview window was resized we need to // update the view on the buffer. Only go back to // the window when needed, otherwise it will always be - // redraw. + // redrawn. if (resized) { no_u_sync++; win_enter(curwin_save, true); -- cgit