From ea70d2ad8581fab6ea8cc264df5d01c799550e52 Mon Sep 17 00:00:00 2001 From: Oleh Volynets Date: Thu, 20 Nov 2025 18:19:31 +0100 Subject: [PATCH] fix(ui2): unset Search highlighting (#36633) Problem: Trying to match the search highlight groups to the Normal highlight for the window can fail when the message highlighting contains a fg/bg that the Normal highlight doesn't (like an error message in cmd will have ErrorMsg highlight instead of MsgArea - which is Normal in cmd.) Solution: Link the search highlight groups to an empty group in 'winhighlight' thus disabling them instead of overriding them with Normal/MsgArea/etc. --- runtime/lua/vim/_extui/shared.lua | 11 ++++++---- test/functional/ui/messages2_spec.lua | 30 ++++++++++++++++++--------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/runtime/lua/vim/_extui/shared.lua b/runtime/lua/vim/_extui/shared.lua index ec1e767a9b..0c9908f12b 100644 --- a/runtime/lua/vim/_extui/shared.lua +++ b/runtime/lua/vim/_extui/shared.lua @@ -81,10 +81,13 @@ function M.check_targets() api.nvim_set_option_value('bufhidden', 'hide', { scope = 'local' }) api.nvim_set_option_value('buftype', 'nofile', { scope = 'local' }) -- Use MsgArea except in the msg window. Hide Search highlighting except in the pager. - local hide = type == 'msg' and 'NormalFloat' or 'MsgArea' - hide = ('Search:%s,CurSearch:%s,IncSearch:%s'):format(hide, hide, hide) - local hl = type == 'msg' and '' or 'Normal:MsgArea' .. (type ~= 'pager' and ',' or '') - hl = hl .. (type ~= 'pager' and hide or '') + local search_hide = 'Search:,CurSearch:,IncSearch:' + local hl = 'Normal:MsgArea,' .. search_hide + if type == 'pager' then + hl = 'Normal:MsgArea' + elseif type == 'msg' then + hl = search_hide + end api.nvim_set_option_value('winhighlight', hl, { scope = 'local' }) end) api.nvim_buf_set_name(M.bufs[type], ('[%s]'):format(type:sub(1, 1):upper() .. type:sub(2))) diff --git a/test/functional/ui/messages2_spec.lua b/test/functional/ui/messages2_spec.lua index 17812fc675..e52b4a9bf6 100644 --- a/test/functional/ui/messages2_spec.lua +++ b/test/functional/ui/messages2_spec.lua @@ -440,21 +440,31 @@ describe('messages2', function() end) it('Search highlights only apply to pager', function() + screen:add_extra_attr_ids({ + [100] = { background = Screen.colors.Blue1, foreground = Screen.colors.Red }, + [101] = { background = Screen.colors.Red1, foreground = Screen.colors.Blue1 }, + }) + command('hi MsgArea guifg=Red guibg=Blue') + command('hi Search guifg=Blue guibg=Red') + command('set hlsearch shortmess+=s') + feed('/foo') + screen:expect([[ + ^ | + {1:~ }|*12 + {9:E486: Pattern not found: foo}{100: }| + ]]) command('set cmdheight=0 | echo "foo"') - feed('/foo') + screen:expect([[ + ^ | + {1:~ }|*12 + {1:~ }{4:foo}| + ]]) + feed('g') screen:expect([[ | {1:~ }|*11 - {1:~ }{4:foo}| - /foo^ | - ]]) - feed('g/foo') - screen:expect([[ - | - {1:~ }|*10 {3: }| - {10:foo} | - /foo^ | + {101:fo^o}{100: }| ]]) end) end)