From 9ecb43b6372feb49d6d497c41aa75d2cce1a1446 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 12 Nov 2023 09:23:34 +0800 Subject: [PATCH] fix(float): apply 'winblend' to title/footer highlight (#25999) --- src/nvim/drawscreen.c | 1 + src/nvim/highlight.c | 44 ++++++++++++++++--------------- test/functional/ui/float_spec.lua | 15 ++++++----- 3 files changed, 33 insertions(+), 27 deletions(-) diff --git a/src/nvim/drawscreen.c b/src/nvim/drawscreen.c index adbe0f473f..1144fa6354 100644 --- a/src/nvim/drawscreen.c +++ b/src/nvim/drawscreen.c @@ -725,6 +725,7 @@ static void win_redr_bordertext(win_T *wp, VirtText vt, int col) if (text == NULL) { break; } + attr = hl_apply_winblend(wp, attr); col += grid_line_puts(col, text, -1, attr); } } diff --git a/src/nvim/highlight.c b/src/nvim/highlight.c index a0114bbbe8..6d6bcacd83 100644 --- a/src/nvim/highlight.c +++ b/src/nvim/highlight.c @@ -323,6 +323,23 @@ int hl_get_ui_attr(int ns_id, int idx, int final_id, bool optional) .id1 = idx, .id2 = final_id }); } +/// Apply 'winblend' to highlight attributes. +/// +/// @param wp The window to get 'winblend' value from. +/// @param attr The original attribute code. +/// +/// @return The attribute code with 'winblend' applied. +int hl_apply_winblend(win_T *wp, int attr) +{ + HlEntry entry = attr_entry(attr); + // if blend= attribute is not set, 'winblend' value overrides it. + if (entry.attr.hl_blend == -1 && wp->w_p_winbl > 0) { + entry.attr.hl_blend = (int)wp->w_p_winbl; + attr = get_attr_entry(entry); + } + return attr; +} + void update_window_hl(win_T *wp, bool invalid) { int ns_id = wp->w_ns_hl; @@ -358,13 +375,8 @@ void update_window_hl(win_T *wp, bool invalid) wp->w_hl_attr_normal = float_win ? HL_ATTR(HLF_NFLOAT) : 0; } - // if blend= attribute is not set, 'winblend' value overrides it. - if (wp->w_floating && wp->w_p_winbl > 0) { - HlEntry entry = attr_entry(wp->w_hl_attr_normal); - if (entry.attr.hl_blend == -1) { - entry.attr.hl_blend = (int)wp->w_p_winbl; - wp->w_hl_attr_normal = get_attr_entry(entry); - } + if (wp->w_floating) { + wp->w_hl_attr_normal = hl_apply_winblend(wp, wp->w_hl_attr_normal); } wp->w_float_config.shadow = false; @@ -375,13 +387,8 @@ void update_window_hl(win_T *wp, bool invalid) attr = hl_get_ui_attr(ns_id, HLF_BORDER, wp->w_float_config.border_hl_ids[i], false); } - HlAttrs a = syn_attr2entry(attr); - if (a.hl_blend == -1 && wp->w_p_winbl > 0) { - HlEntry entry = attr_entry(attr); - a.hl_blend = entry.attr.hl_blend = (int)wp->w_p_winbl; - attr = get_attr_entry(entry); - } - if (a.hl_blend > 0) { + attr = hl_apply_winblend(wp, attr); + if (syn_attr2entry(attr).hl_blend > 0) { wp->w_float_config.shadow = true; } wp->w_float_config.border_attr[i] = attr; @@ -400,13 +407,8 @@ void update_window_hl(win_T *wp, bool invalid) 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 = attr_entry(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); - } + if (wp->w_floating) { + wp->w_hl_attr_normalnc = hl_apply_winblend(wp, wp->w_hl_attr_normalnc); } } diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index c9f28f430a..2902b4a4a5 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -9198,6 +9198,9 @@ describe('float window', function() [20] = {background = Screen.colors.White, foreground = Screen.colors.Gray0}; [21] = {background = Screen.colors.White, bold = true, foreground = tonumber('0x00007f')}; [22] = {background = Screen.colors.Gray90, foreground = Screen.colors.Gray0}; + [23] = {blend = 100, bold = true, foreground = Screen.colors.Magenta}; + [24] = {foreground = tonumber('0x7f007f'), bold = true, background = Screen.colors.White}; + [25] = {foreground = tonumber('0x7f007f'), bold = true, background = Screen.colors.Grey90}; }) insert([[ Lorem ipsum dolor sit amet, consectetur @@ -9483,8 +9486,8 @@ describe('float window', function() ]]) end - -- Check that 'winblend' applies to border - meths.win_set_config(win, {border='single'}) + -- Check that 'winblend' applies to border/title/footer + meths.win_set_config(win, {border='single', title='Title', footer='Footer'}) meths.set_option_value('winblend', 100, {win=win.id}) meths.set_option_value("cursorline", true, {win=0}) command('hi clear VertSplit') @@ -9513,21 +9516,21 @@ describe('float window', function() ## grid 3 | ## grid 4 - {17:┌───────────────┐}| + {17:┌}{23:Title}{17:──────────┐}| {17:│}{11:popup text}{18: }{17:│}| {17:│}{19:~ }{17:│}| {17:│}{19:~ }{17:│}| - {17:└───────────────┘}| + {17:└}{23:Footer}{17:─────────┘}| ]], float_pos={[4] = {{id = 1001}, "NW", 1, 2, 5, true}}} else screen:expect([[ Ut enim ad minim veniam, quis nostrud | exercitation ullamco laboris nisi ut aliquip ex | - ea co{20:┌───────────────┐}Duis aute irure dolor in | + ea co{20:┌}{24:Title}{20:──────────┐}Duis aute irure dolor in | repre{20:│}{5:popup}{6:it i}{5:text}{20:lu│}tate velit esse cillum | dolor{20:│}{21:~}{20:eu fugiat null│} pariatur. Excepteur sint | occae{20:│}{21:~}{20:t cupidatat no│} proident, sunt in culpa | - {16:^qui o}{22:└───────────────┘}{16:ollit anim id est }| + {16:^qui o}{22:└}{25:Footer}{22:─────────┘}{16:ollit anim id est }| laborum. | | ]])