Merge pull request #24449 from neovim/backport-24448-to-release-0.9

[Backport release-0.9] fix(highlight): make CurSearch work properly with 'winhl'
This commit is contained in:
zeertzjq
2023-07-23 21:56:01 +08:00
committed by GitHub
4 changed files with 27 additions and 6 deletions

View File

@@ -151,6 +151,7 @@ static const char *highlight_init_both[] = {
"default link QuickFixLine Search", "default link QuickFixLine Search",
"default link CursorLineSign SignColumn", "default link CursorLineSign SignColumn",
"default link CursorLineFold FoldColumn", "default link CursorLineFold FoldColumn",
"default link CurSearch Search",
"default link PmenuKind Pmenu", "default link PmenuKind Pmenu",
"default link PmenuKindSel PmenuSel", "default link PmenuKindSel PmenuSel",
"default link PmenuExtra Pmenu", "default link PmenuExtra Pmenu",
@@ -2163,8 +2164,7 @@ void highlight_changed(void)
id_S = final_id; id_S = final_id;
} }
highlight_attr[hlf] = hl_get_ui_attr(ns_id, hlf, final_id, highlight_attr[hlf] = hl_get_ui_attr(ns_id, hlf, final_id, hlf == HLF_INACTIVE);
(hlf == HLF_INACTIVE || hlf == HLF_LC));
if (highlight_attr[hlf] != highlight_attr_last[hlf]) { if (highlight_attr[hlf] != highlight_attr_last[hlf]) {
if (hlf == HLF_MSG) { if (hlf == HLF_MSG) {

View File

@@ -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 // Highlight the match were the cursor is using the CurSearch
// group. // group.
if (shl == search_hl && shl->has_cursor && (HL_ATTR(HLF_LC) || win_hl_attr(wp, HLF_LC))) { if (shl == search_hl && shl->has_cursor) {
shl->attr_cur = win_hl_attr(wp, HLF_LC) ? win_hl_attr(wp, HLF_LC) : HL_ATTR(HLF_LC); shl->attr_cur = win_hl_attr(wp, HLF_LC);
} else { } else {
shl->attr_cur = shl->attr; shl->attr_cur = shl->attr;
} }

View File

@@ -110,7 +110,8 @@ static void redraw_for_cursorcolumn(win_T *wp)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
if ((wp->w_valid & VALID_VIRTCOL) == 0 && !pum_visible()) { 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 // When 'cursorcolumn' is set or "CurSearch" is in use
// need to redraw with UPD_SOME_VALID. // need to redraw with UPD_SOME_VALID.
redraw_later(wp, UPD_SOME_VALID); redraw_later(wp, UPD_SOME_VALID);

View File

@@ -56,7 +56,7 @@ describe('search highlighting', function()
}} }}
end) end)
it('works', function() local function test_search_hl()
insert([[ insert([[
some text some text
more textstuff more textstuff
@@ -109,6 +109,26 @@ describe('search highlighting', function()
{1:~ }| {1:~ }|
:nohlsearch | :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) end)
describe('CurSearch highlight', function() describe('CurSearch highlight', function()