neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 59289fb987bd51b072f91ae0de8ee8515bf07e21
parent 183147a906fcf352e393dea546e7a683f7c068c3
Author: zeertzjq <zeertzjq@outlook.com>
Date:   Sun, 23 Jul 2023 21:36:32 +0800

fix(highlight): make CurSearch work properly with 'winhl' (#24448)


Diffstat:
Msrc/nvim/highlight_group.c | 4++--
Msrc/nvim/match.c | 4++--
Msrc/nvim/move.c | 3++-
Mtest/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 @@ -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 @@ -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 @@ -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 @@ -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()