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

This commit is contained in:
zeertzjq 2023-07-23 21:36:32 +08:00 committed by GitHub
parent 183147a906
commit 59289fb987
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 6 deletions

View File

@ -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) {

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
// 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;
}

View File

@ -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);

View File

@ -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()