From 03ca36d1f8d027c95edd46f3127284e9a3577990 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 10 May 2023 23:46:50 +0800 Subject: [PATCH] fix(highlight): apply 'winblend' to NormalNC (#23555) --- src/nvim/highlight.c | 9 +++++ test/functional/ui/float_spec.lua | 63 +++++++++++++++++++++++++++++-- 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/src/nvim/highlight.c b/src/nvim/highlight.c index e2f3e2aafa..cc332c530d 100644 --- a/src/nvim/highlight.c +++ b/src/nvim/highlight.c @@ -398,6 +398,15 @@ void update_window_hl(win_T *wp, bool invalid) } else { wp->w_hl_attr_normalnc = hl_def[HLF_INACTIVE]; } + + // if blend= attribute is not set, 'winblend' value overrides it. + if (wp->w_floating && wp->w_p_winbl > 0) { + HlEntry entry = kv_A(attr_entries, wp->w_hl_attr_normalnc); + if (entry.attr.hl_blend == -1) { + entry.attr.hl_blend = (int)wp->w_p_winbl; + wp->w_hl_attr_normalnc = get_attr_entry(entry); + } + } } void update_ns_hl(int ns_id) diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index 28c16642f1..46a079d9ff 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -8079,10 +8079,13 @@ describe('float window', function() [6] = {foreground = tonumber('0x332533'), background = tonumber('0xfff1ff')}, [7] = {background = tonumber('0xffcfff'), bold = true, foreground = tonumber('0x0000d8')}, [8] = {background = Screen.colors.LightMagenta, bold = true, foreground = Screen.colors.Blue1}, - [9] = {background = Screen.colors.LightMagenta, blend=30}, - [10] = {foreground = Screen.colors.Red, background = Screen.colors.LightMagenta, blend=0}, - [11] = {foreground = Screen.colors.Red, background = Screen.colors.LightMagenta, blend=80}, - [12] = {background = Screen.colors.LightMagenta, bold = true, foreground = Screen.colors.Blue1, blend=30}, + [9] = {background = Screen.colors.LightMagenta, blend = 30}, + [10] = {foreground = Screen.colors.Red, background = Screen.colors.LightMagenta, blend = 0}, + [11] = {foreground = Screen.colors.Red, background = Screen.colors.LightMagenta, blend = 80}, + [12] = {background = Screen.colors.LightMagenta, bold = true, foreground = Screen.colors.Blue1, blend = 30}, + [13] = {background = Screen.colors.LightGray, blend = 30}, + [14] = {foreground = Screen.colors.Grey0, background = Screen.colors.Grey88}, + [15] = {foreground = tonumber('0x939393'), background = Screen.colors.Grey88}, }) insert([[ Lorem ipsum dolor sit amet, consectetur @@ -8184,6 +8187,58 @@ describe('float window', function() ]]) end + -- Check that 'winblend' works with NormalNC highlight + meths.set_option_value('winhighlight', 'NormalNC:Visual', {win = win}) + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:--------------------------------------------------]| + [2:--------------------------------------------------]| + [2:--------------------------------------------------]| + [2:--------------------------------------------------]| + [2:--------------------------------------------------]| + [2:--------------------------------------------------]| + [2:--------------------------------------------------]| + [2:--------------------------------------------------]| + [3:--------------------------------------------------]| + ## grid 2 + Ut enim ad minim veniam, quis nostrud | + exercitation ullamco laboris nisi ut aliquip ex | + ea commodo consequat. Duis aute irure dolor in | + reprehenderit in voluptate velit esse cillum | + dolore eu fugiat nulla pariatur. Excepteur sint | + occaecat cupidatat non proident, sunt in culpa | + qui officia deserunt mollit anim id est | + laborum^. | + ## grid 3 + | + ## grid 5 + {13:test }| + {13: }| + {13:popup text }| + ]], float_pos={ + [5] = {{id = 1002}, "NW", 1, 2, 5, true, 50}; + }} + else + screen:expect([[ + Ut enim ad minim veniam, quis nostrud | + exercitation ullamco laboris nisi ut aliquip ex | + ea co{14:test}{15:o consequat}. Duis aute irure dolor in | + repre{15:henderit in vol}uptate velit esse cillum | + dolor{14:popup}{15:fugi}{14:text}{15:ul}la pariatur. Excepteur sint | + occaecat cupidatat non proident, sunt in culpa | + qui officia deserunt mollit anim id est | + laborum^. | + | + ]]) + end + + -- Also test with global NormalNC highlight + meths.set_option_value('winhighlight', '', {win = win}) + command('hi link NormalNC Visual') + screen:expect_unchanged(true) + command('hi clear NormalNC') + command('hi SpecialRegion guifg=Red blend=0') meths.buf_add_highlight(buf, -1, "SpecialRegion", 2, 0, -1) if multigrid then