diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-07-23 21:36:32 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-23 21:36:32 +0800 |
commit | 59289fb987bd51b072f91ae0de8ee8515bf07e21 (patch) | |
tree | 807ca667f23e0fda30bdb99626b14c094cd4c52a | |
parent | 183147a906fcf352e393dea546e7a683f7c068c3 (diff) | |
download | rneovim-59289fb987bd51b072f91ae0de8ee8515bf07e21.tar.gz rneovim-59289fb987bd51b072f91ae0de8ee8515bf07e21.tar.bz2 rneovim-59289fb987bd51b072f91ae0de8ee8515bf07e21.zip |
fix(highlight): make CurSearch work properly with 'winhl' (#24448)
-rw-r--r-- | src/nvim/highlight_group.c | 4 | ||||
-rw-r--r-- | src/nvim/match.c | 4 | ||||
-rw-r--r-- | src/nvim/move.c | 3 | ||||
-rw-r--r-- | test/functional/ui/searchhl_spec.lua | 22 |
4 files changed, 27 insertions, 6 deletions
diff --git a/src/nvim/highlight_group.c b/src/nvim/highlight_group.c index 8bcfbc8069..9ae928a0d2 100644 --- a/src/nvim/highlight_group.c +++ b/src/nvim/highlight_group.c @@ -162,6 +162,7 @@ static const char *highlight_init_both[] = { "default link QuickFixLine Search", "default link CursorLineSign SignColumn", "default link CursorLineFold FoldColumn", + "default link CurSearch Search", "default link PmenuKind Pmenu", "default link PmenuKindSel PmenuSel", "default link PmenuExtra Pmenu", @@ -2163,8 +2164,7 @@ void highlight_changed(void) id_S = final_id; } - highlight_attr[hlf] = hl_get_ui_attr(ns_id, hlf, final_id, - (hlf == HLF_INACTIVE || hlf == HLF_LC)); + highlight_attr[hlf] = hl_get_ui_attr(ns_id, hlf, final_id, hlf == HLF_INACTIVE); if (highlight_attr[hlf] != highlight_attr_last[hlf]) { if (hlf == HLF_MSG) { diff --git a/src/nvim/match.c b/src/nvim/match.c index ece4de2199..d0e7fe0ef9 100644 --- a/src/nvim/match.c +++ b/src/nvim/match.c @@ -716,8 +716,8 @@ int update_search_hl(win_T *wp, linenr_T lnum, colnr_T col, char **line, match_T } // Highlight the match were the cursor is using the CurSearch // group. - if (shl == search_hl && shl->has_cursor && (HL_ATTR(HLF_LC) || win_hl_attr(wp, HLF_LC))) { - shl->attr_cur = win_hl_attr(wp, HLF_LC) ? win_hl_attr(wp, HLF_LC) : HL_ATTR(HLF_LC); + if (shl == search_hl && shl->has_cursor) { + shl->attr_cur = win_hl_attr(wp, HLF_LC); } else { shl->attr_cur = shl->attr; } diff --git a/src/nvim/move.c b/src/nvim/move.c index 03d7f95bba..0ed30070a5 100644 --- a/src/nvim/move.c +++ b/src/nvim/move.c @@ -147,7 +147,8 @@ static void redraw_for_cursorcolumn(win_T *wp) FUNC_ATTR_NONNULL_ALL { if ((wp->w_valid & VALID_VIRTCOL) == 0 && !pum_visible()) { - if (wp->w_p_cuc || ((HL_ATTR(HLF_LC) || win_hl_attr(wp, HLF_LC)) && using_hlsearch())) { + if (wp->w_p_cuc + || (win_hl_attr(wp, HLF_LC) != win_hl_attr(wp, HLF_L) && using_hlsearch())) { // When 'cursorcolumn' is set or "CurSearch" is in use // need to redraw with UPD_SOME_VALID. redraw_later(wp, UPD_SOME_VALID); diff --git a/test/functional/ui/searchhl_spec.lua b/test/functional/ui/searchhl_spec.lua index 1e42689200..ec1ebbe4ca 100644 --- a/test/functional/ui/searchhl_spec.lua +++ b/test/functional/ui/searchhl_spec.lua @@ -56,7 +56,7 @@ describe('search highlighting', function() }} end) - it('works', function() + local function test_search_hl() insert([[ some text more textstuff @@ -109,6 +109,26 @@ describe('search highlighting', function() {1:~ }| :nohlsearch | ]]) + end + + it("works when 'winhighlight' is not set", function() + test_search_hl() + end) + + it("works when 'winhighlight' doesn't change Search highlight", function() + command('setlocal winhl=NonText:Underlined') + local attrs = screen:get_default_attr_ids() + attrs[1] = {foreground = Screen.colors.SlateBlue, underline = true} + screen:set_default_attr_ids(attrs) + test_search_hl() + end) + + it("works when 'winhighlight' changes Search highlight", function() + command('setlocal winhl=Search:Underlined') + local attrs = screen:get_default_attr_ids() + attrs[2] = {foreground = Screen.colors.SlateBlue, underline = true} + screen:set_default_attr_ids(attrs) + test_search_hl() end) describe('CurSearch highlight', function() |