From 8450752f46e1482bf34b7f05e484cca740f61075 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 9 Oct 2024 08:15:14 +0800 Subject: vim-patch:9.1.0771: completion attribute hl_group is confusing Problem: Currently completion attribute hl_group is combined with all items, which is redundant and confusing with kind_hlgroup Solution: Renamed to abbr_hlgroup and combine it only with the abbr item (glepnir). closes: vim/vim#15818 https://github.com/vim/vim/commit/0fe17f8ffbd2588ecd2bf42dced556897bc64f89 Co-authored-by: glepnir --- src/nvim/popupmenu.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'src/nvim/popupmenu.c') diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c index ddcb819054..3f64e841e2 100644 --- a/src/nvim/popupmenu.c +++ b/src/nvim/popupmenu.c @@ -654,11 +654,14 @@ void pum_redraw(void) int item_type = order[j]; hlf = hlfs[item_type]; attr = win_hl_attr(curwin, (int)hlf); - if (pum_array[idx].pum_user_hlattr > 0) { - attr = hl_combine_attr(attr, pum_array[idx].pum_user_hlattr); + int orig_attr = attr; + int user_abbr_hlattr = pum_array[idx].pum_user_abbr_hlattr; + int user_kind_hlattr = pum_array[idx].pum_user_kind_hlattr; + if (item_type == CPT_ABBR && user_abbr_hlattr > 0) { + attr = hl_combine_attr(attr, user_abbr_hlattr); } - if (item_type == CPT_KIND && pum_array[idx].pum_user_kind_hlattr > 0) { - attr = hl_combine_attr(attr, pum_array[idx].pum_user_kind_hlattr); + if (item_type == CPT_KIND && user_kind_hlattr > 0) { + attr = hl_combine_attr(attr, user_kind_hlattr); } int width = 0; char *s = NULL; @@ -684,8 +687,10 @@ void pum_redraw(void) *p = saved; } - int user_hlattr = pum_array[idx].pum_user_hlattr; - int *attrs = pum_compute_text_attrs(st, hlf, user_hlattr); + int *attrs = NULL; + if (item_type == CPT_ABBR) { + attrs = pum_compute_text_attrs(st, hlf, user_abbr_hlattr); + } if (pum_rl) { char *rt = reverse_text(st); @@ -727,7 +732,10 @@ void pum_redraw(void) grid_col += width; } - xfree(attrs); + if (attrs != NULL) { + xfree(attrs); + attrs = NULL; + } if (*p != TAB) { break; @@ -735,10 +743,10 @@ void pum_redraw(void) // Display two spaces for a Tab. if (pum_rl) { - grid_line_puts(grid_col - 1, " ", 2, attr); + grid_line_puts(grid_col - 1, " ", 2, orig_attr); grid_col -= 2; } else { - grid_line_puts(grid_col, " ", 2, attr); + grid_line_puts(grid_col, " ", 2, orig_attr); grid_col += 2; } totwidth += 2; @@ -772,7 +780,7 @@ void pum_redraw(void) grid_line_fill(col_off - basic_width - n + 1, grid_col + 1, schar_from_ascii(' '), attr); grid_col = col_off - basic_width - n; } else { - grid_line_fill(grid_col, col_off + basic_width + n, schar_from_ascii(' '), attr); + grid_line_fill(grid_col, col_off + basic_width + n, schar_from_ascii(' '), orig_attr); grid_col = col_off + basic_width + n; } totwidth = basic_width + n; -- cgit From 9612b3a9053ae2dfe5a4321a5dd0af249c281543 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 10 Oct 2024 06:49:37 +0800 Subject: vim-patch:9.1.0772: some missing changes from v9.1.0771 Problem: some missing changes from v9.1.0771 Solution: use correct highlighting attribute and adjust comments (glepnir) closes: vim/vim#15836 https://github.com/vim/vim/commit/7baa014d0f73c3b2c6831471d047220633651238 Co-authored-by: glepnir --- src/nvim/popupmenu.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/nvim/popupmenu.c') diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c index 3f64e841e2..ed4c9f3056 100644 --- a/src/nvim/popupmenu.c +++ b/src/nvim/popupmenu.c @@ -733,8 +733,7 @@ void pum_redraw(void) } if (attrs != NULL) { - xfree(attrs); - attrs = NULL; + XFREE_CLEAR(attrs); } if (*p != TAB) { @@ -743,10 +742,10 @@ void pum_redraw(void) // Display two spaces for a Tab. if (pum_rl) { - grid_line_puts(grid_col - 1, " ", 2, orig_attr); + grid_line_puts(grid_col - 1, " ", 2, attr); grid_col -= 2; } else { - grid_line_puts(grid_col, " ", 2, orig_attr); + grid_line_puts(grid_col, " ", 2, attr); grid_col += 2; } totwidth += 2; @@ -777,10 +776,12 @@ void pum_redraw(void) } if (pum_rl) { - grid_line_fill(col_off - basic_width - n + 1, grid_col + 1, schar_from_ascii(' '), attr); + grid_line_fill(col_off - basic_width - n + 1, grid_col + 1, + schar_from_ascii(' '), orig_attr); grid_col = col_off - basic_width - n; } else { - grid_line_fill(grid_col, col_off + basic_width + n, schar_from_ascii(' '), orig_attr); + grid_line_fill(grid_col, col_off + basic_width + n, + schar_from_ascii(' '), orig_attr); grid_col = col_off + basic_width + n; } totwidth = basic_width + n; -- cgit From a0e3fe57417f0b7c8de60dcebe44d0cf034c4b9a Mon Sep 17 00:00:00 2001 From: Riley Bruins Date: Thu, 10 Oct 2024 23:26:25 -0700 Subject: feat(ui): cascading style inheritance for Pmenu* highlights #29980 - `PmenuSel` and `PmenuMatch` inherit from `Pmenu` - `PmenuMatchSel` inherits from both `PmenuSel` and `PmenuMatch` --- src/nvim/popupmenu.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/nvim/popupmenu.c') diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c index ed4c9f3056..87ef6a27ad 100644 --- a/src/nvim/popupmenu.c +++ b/src/nvim/popupmenu.c @@ -480,13 +480,19 @@ static int *pum_compute_text_attrs(char *text, hlf_T hlf, int user_hlattr) for (int i = 0; i < ga->ga_len; i++) { if (char_pos == ((uint32_t *)ga->ga_data)[i]) { new_attr = win_hl_attr(curwin, hlf == HLF_PSI ? HLF_PMSI : HLF_PMNI); + new_attr = hl_combine_attr(win_hl_attr(curwin, HLF_PMNI), new_attr); + new_attr = hl_combine_attr(win_hl_attr(curwin, (int)hlf), new_attr); break; } } } else if (matched_start && ptr < text + leader_len) { new_attr = win_hl_attr(curwin, hlf == HLF_PSI ? HLF_PMSI : HLF_PMNI); + new_attr = hl_combine_attr(win_hl_attr(curwin, HLF_PMNI), new_attr); + new_attr = hl_combine_attr(win_hl_attr(curwin, (int)hlf), new_attr); } + new_attr = hl_combine_attr(win_hl_attr(curwin, HLF_PNI), new_attr); + if (user_hlattr > 0) { new_attr = hl_combine_attr(new_attr, user_hlattr); } @@ -629,6 +635,7 @@ void pum_redraw(void) const hlf_T *const hlfs = (idx == pum_selected) ? hlfsSel : hlfsNorm; hlf_T hlf = hlfs[0]; // start with "word" highlight int attr = win_hl_attr(curwin, (int)hlf); + attr = hl_combine_attr(win_hl_attr(curwin, HLF_PNI), attr); grid_line_start(&pum_grid, row); @@ -663,6 +670,7 @@ void pum_redraw(void) if (item_type == CPT_KIND && user_kind_hlattr > 0) { attr = hl_combine_attr(attr, user_kind_hlattr); } + attr = hl_combine_attr(win_hl_attr(curwin, HLF_PNI), attr); int width = 0; char *s = NULL; p = pum_get_item(idx, item_type); -- cgit From d24fb72c335be905d0b7f2c67f9b988f07703d1f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 28 Oct 2024 14:29:59 +0800 Subject: fix(pum): don't select item when clicking to the left/right (#30967) Problem: Selecting an item in the right-click menu when clicking to the left/right of it is confusing, especially in a UI that doesn't support 'mousemoveevent'. Solution: Don't select an item when clicking to the left/right of the right-click menu. --- src/nvim/popupmenu.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/nvim/popupmenu.c') diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c index 87ef6a27ad..529d65c5dc 100644 --- a/src/nvim/popupmenu.c +++ b/src/nvim/popupmenu.c @@ -1358,14 +1358,15 @@ static void pum_select_mouse_pos(void) if (mouse_grid == pum_grid.handle) { pum_selected = mouse_row; return; - } else if (mouse_grid != pum_anchor_grid) { + } else if (mouse_grid != pum_anchor_grid || mouse_col < pum_grid.comp_col + || mouse_col >= pum_grid.comp_col + pum_grid.comp_width) { pum_selected = -1; return; } - int idx = mouse_row - pum_row; + int idx = mouse_row - pum_grid.comp_row; - if (idx < 0 || idx >= pum_height) { + if (idx < 0 || idx >= pum_grid.comp_height) { pum_selected = -1; } else if (*pum_array[idx].pum_text != NUL) { pum_selected = idx; -- cgit From ed3fb1bb9ad97435c50655ee8de71b2d7d67d01c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 3 Nov 2024 08:27:15 +0800 Subject: vim-patch:9.1.0830: using wrong highlight group for spaces for popupmenu (#31054) Problem: using wrong highlight group for spaces for popupmenu Solution: use original attribute instead of combined attributed (glepnir) closes: vim/vim#15978 https://github.com/vim/vim/commit/bc10be7a4060748ed1876ab91cf53a2a8701ac13 Co-authored-by: glepnir --- src/nvim/popupmenu.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/nvim/popupmenu.c') diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c index 529d65c5dc..7df6a1a5d7 100644 --- a/src/nvim/popupmenu.c +++ b/src/nvim/popupmenu.c @@ -657,11 +657,14 @@ void pum_redraw(void) pum_align_order(order); int basic_width = items_width_array[order[0]]; // first item width bool last_isabbr = order[2] == CPT_ABBR; + int orig_attr = -1; + for (int j = 0; j < 3; j++) { int item_type = order[j]; hlf = hlfs[item_type]; attr = win_hl_attr(curwin, (int)hlf); - int orig_attr = attr; + attr = hl_combine_attr(win_hl_attr(curwin, HLF_PNI), attr); + orig_attr = attr; int user_abbr_hlattr = pum_array[idx].pum_user_abbr_hlattr; int user_kind_hlattr = pum_array[idx].pum_user_kind_hlattr; if (item_type == CPT_ABBR && user_abbr_hlattr > 0) { @@ -670,7 +673,6 @@ void pum_redraw(void) if (item_type == CPT_KIND && user_kind_hlattr > 0) { attr = hl_combine_attr(attr, user_kind_hlattr); } - attr = hl_combine_attr(win_hl_attr(curwin, HLF_PNI), attr); int width = 0; char *s = NULL; p = pum_get_item(idx, item_type); @@ -796,9 +798,9 @@ void pum_redraw(void) } if (pum_rl) { - grid_line_fill(col_off - pum_width + 1, grid_col + 1, schar_from_ascii(' '), attr); + grid_line_fill(col_off - pum_width + 1, grid_col + 1, schar_from_ascii(' '), orig_attr); } else { - grid_line_fill(grid_col, col_off + pum_width, schar_from_ascii(' '), attr); + grid_line_fill(grid_col, col_off + pum_width, schar_from_ascii(' '), orig_attr); } if (pum_scrollbar > 0) { -- cgit