fix(float): missing default highlight for title

Problem: there is missing default title highlight when highlight not defined in title text chunk.

Solution: when attr is not set use default title highlight group.
This commit is contained in:
glepnir 2024-05-03 15:53:13 +08:00
parent 4e5c633ed4
commit 8b2b1fba2a
5 changed files with 27 additions and 22 deletions

View File

@ -3270,13 +3270,15 @@ nvim_open_win({buffer}, {enter}, {config}) *nvim_open_win()*
< <
• title: Title (optional) in window border, string or list. • title: Title (optional) in window border, string or list.
List should consist of `[text, highlight]` tuples. If List should consist of `[text, highlight]` tuples. If
string, the default highlight group is `FloatTitle`. string, or a tuple lacks a highlight, the default
highlight group is `FloatTitle`.
• title_pos: Title position. Must be set with `title` • title_pos: Title position. Must be set with `title`
option. Value can be one of "left", "center", or "right". option. Value can be one of "left", "center", or "right".
Default is `"left"`. Default is `"left"`.
• footer: Footer (optional) in window border, string or • footer: Footer (optional) in window border, string or
list. List should consist of `[text, highlight]` tuples. list. List should consist of `[text, highlight]` tuples.
If string, the default highlight group is `FloatFooter`. If string, or a tuple lacks a highlight, the default
highlight group is `FloatFooter`.
• footer_pos: Footer position. Must be set with `footer` • footer_pos: Footer position. Must be set with `footer`
option. Value can be one of "left", "center", or "right". option. Value can be one of "left", "center", or "right".
Default is `"left"`. Default is `"left"`.

View File

@ -1731,13 +1731,15 @@ function vim.api.nvim_open_term(buffer, opts) end
--- ---
--- • title: Title (optional) in window border, string or list. --- • title: Title (optional) in window border, string or list.
--- List should consist of `[text, highlight]` tuples. If --- List should consist of `[text, highlight]` tuples. If
--- string, the default highlight group is `FloatTitle`. --- string, or a tuple lacks a highlight, the default
--- highlight group is `FloatTitle`.
--- • title_pos: Title position. Must be set with `title` --- • title_pos: Title position. Must be set with `title`
--- option. Value can be one of "left", "center", or "right". --- option. Value can be one of "left", "center", or "right".
--- Default is `"left"`. --- Default is `"left"`.
--- • footer: Footer (optional) in window border, string or --- • footer: Footer (optional) in window border, string or
--- list. List should consist of `[text, highlight]` tuples. --- list. List should consist of `[text, highlight]` tuples.
--- If string, the default highlight group is `FloatFooter`. --- If string, or a tuple lacks a highlight, the default
--- highlight group is `FloatFooter`.
--- • footer_pos: Footer position. Must be set with `footer` --- • footer_pos: Footer position. Must be set with `footer`
--- option. Value can be one of "left", "center", or "right". --- option. Value can be one of "left", "center", or "right".
--- Default is `"left"`. --- Default is `"left"`.

View File

@ -189,13 +189,13 @@
/// ``` /// ```
/// - title: Title (optional) in window border, string or list. /// - title: Title (optional) in window border, string or list.
/// List should consist of `[text, highlight]` tuples. /// List should consist of `[text, highlight]` tuples.
/// If string, the default highlight group is `FloatTitle`. /// If string, or a tuple lacks a highlight, the default highlight group is `FloatTitle`.
/// - title_pos: Title position. Must be set with `title` option. /// - title_pos: Title position. Must be set with `title` option.
/// Value can be one of "left", "center", or "right". /// Value can be one of "left", "center", or "right".
/// Default is `"left"`. /// Default is `"left"`.
/// - footer: Footer (optional) in window border, string or list. /// - footer: Footer (optional) in window border, string or list.
/// List should consist of `[text, highlight]` tuples. /// List should consist of `[text, highlight]` tuples.
/// If string, the default highlight group is `FloatFooter`. /// If string, or a tuple lacks a highlight, the default highlight group is `FloatFooter`.
/// - footer_pos: Footer position. Must be set with `footer` option. /// - footer_pos: Footer position. Must be set with `footer` option.
/// Value can be one of "left", "center", or "right". /// Value can be one of "left", "center", or "right".
/// Default is `"left"`. /// Default is `"left"`.
@ -851,7 +851,6 @@ static void parse_bordertext(Object bordertext, BorderTextType bordertext_type,
bool *is_present; bool *is_present;
VirtText *chunks; VirtText *chunks;
int *width; int *width;
int default_hl_id;
switch (bordertext_type) { switch (bordertext_type) {
case kBorderTextTitle: case kBorderTextTitle:
if (fconfig->title) { if (fconfig->title) {
@ -861,7 +860,6 @@ static void parse_bordertext(Object bordertext, BorderTextType bordertext_type,
is_present = &fconfig->title; is_present = &fconfig->title;
chunks = &fconfig->title_chunks; chunks = &fconfig->title_chunks;
width = &fconfig->title_width; width = &fconfig->title_width;
default_hl_id = syn_check_group(S_LEN("FloatTitle"));
break; break;
case kBorderTextFooter: case kBorderTextFooter:
if (fconfig->footer) { if (fconfig->footer) {
@ -871,7 +869,6 @@ static void parse_bordertext(Object bordertext, BorderTextType bordertext_type,
is_present = &fconfig->footer; is_present = &fconfig->footer;
chunks = &fconfig->footer_chunks; chunks = &fconfig->footer_chunks;
width = &fconfig->footer_width; width = &fconfig->footer_width;
default_hl_id = syn_check_group(S_LEN("FloatFooter"));
break; break;
} }
@ -881,7 +878,7 @@ static void parse_bordertext(Object bordertext, BorderTextType bordertext_type,
return; return;
} }
kv_push(*chunks, ((VirtTextChunk){ .text = xstrdup(bordertext.data.string.data), kv_push(*chunks, ((VirtTextChunk){ .text = xstrdup(bordertext.data.string.data),
.hl_id = default_hl_id })); .hl_id = -1 }));
*width = (int)mb_string2cells(bordertext.data.string.data); *width = (int)mb_string2cells(bordertext.data.string.data);
*is_present = true; *is_present = true;
return; return;

View File

@ -65,6 +65,7 @@
#include "nvim/autocmd.h" #include "nvim/autocmd.h"
#include "nvim/autocmd_defs.h" #include "nvim/autocmd_defs.h"
#include "nvim/buffer.h" #include "nvim/buffer.h"
#include "nvim/buffer_defs.h"
#include "nvim/charset.h" #include "nvim/charset.h"
#include "nvim/cmdexpand.h" #include "nvim/cmdexpand.h"
#include "nvim/cursor.h" #include "nvim/cursor.h"
@ -715,14 +716,17 @@ void end_search_hl(void)
screen_search_hl.rm.regprog = NULL; screen_search_hl.rm.regprog = NULL;
} }
static void win_redr_bordertext(win_T *wp, VirtText vt, int col) static void win_redr_bordertext(win_T *wp, VirtText vt, int col, BorderTextType bt)
{ {
for (size_t i = 0; i < kv_size(vt);) { for (size_t i = 0; i < kv_size(vt);) {
int attr = 0; int attr = -1;
char *text = next_virt_text_chunk(vt, &i, &attr); char *text = next_virt_text_chunk(vt, &i, &attr);
if (text == NULL) { if (text == NULL) {
break; break;
} }
if (attr == -1) { // No highlight specified.
attr = wp->w_ns_hl_attr[bt == kBorderTextTitle ? HLF_BTITLE : HLF_BFOOTER];
}
attr = hl_apply_winblend(wp, attr); attr = hl_apply_winblend(wp, attr);
col += grid_line_puts(col, text, -1, attr); col += grid_line_puts(col, text, -1, attr);
} }
@ -773,7 +777,7 @@ static void win_redr_border(win_T *wp)
if (wp->w_config.title) { if (wp->w_config.title) {
int title_col = win_get_bordertext_col(icol, wp->w_config.title_width, int title_col = win_get_bordertext_col(icol, wp->w_config.title_width,
wp->w_config.title_pos); wp->w_config.title_pos);
win_redr_bordertext(wp, wp->w_config.title_chunks, title_col); win_redr_bordertext(wp, wp->w_config.title_chunks, title_col, kBorderTextTitle);
} }
if (adj[1]) { if (adj[1]) {
grid_line_put_schar(icol + adj[3], chars[2], attrs[2]); grid_line_put_schar(icol + adj[3], chars[2], attrs[2]);
@ -809,7 +813,7 @@ static void win_redr_border(win_T *wp)
if (wp->w_config.footer) { if (wp->w_config.footer) {
int footer_col = win_get_bordertext_col(icol, wp->w_config.footer_width, int footer_col = win_get_bordertext_col(icol, wp->w_config.footer_width,
wp->w_config.footer_pos); wp->w_config.footer_pos);
win_redr_bordertext(wp, wp->w_config.footer_chunks, footer_col); win_redr_bordertext(wp, wp->w_config.footer_chunks, footer_col, kBorderTextFooter);
} }
if (adj[1]) { if (adj[1]) {
grid_line_put_schar(icol + adj[3], chars[4], attrs[4]); grid_line_put_schar(icol + adj[3], chars[4], attrs[4]);

View File

@ -2127,7 +2127,7 @@ describe('float window', function()
## grid 3 ## grid 3
| |
## grid 4 ## grid 4
{5:}🦄BB{5:}| {5:}{11:🦄BB}{5:}|
{5:}{1: halloj! }{5:}| {5:}{1: halloj! }{5:}|
{5:}{1: BORDAA }{5:}| {5:}{1: BORDAA }{5:}|
{5:}| {5:}|
@ -2141,7 +2141,7 @@ describe('float window', function()
screen:expect{grid=[[ screen:expect{grid=[[
^ | ^ |
{0:~ }| {0:~ }|
{0:~ }{5:}🦄BB{5:}{0: }| {0:~ }{5:}{11:🦄BB}{5:}{0: }|
{0:~ }{5:}{1: halloj! }{5:}{0: }| {0:~ }{5:}{1: halloj! }{5:}{0: }|
{0:~ }{5:}{1: BORDAA }{5:}{0: }| {0:~ }{5:}{1: BORDAA }{5:}{0: }|
{0:~ }{5:}{0: }| {0:~ }{5:}{0: }|
@ -2275,7 +2275,7 @@ describe('float window', function()
{5:}| {5:}|
{5:}{1: halloj! }{5:}| {5:}{1: halloj! }{5:}|
{5:}{1: BORDAA }{5:}| {5:}{1: BORDAA }{5:}|
{5:}🦄BB{5:}| {5:}{11:🦄BB}{5:}|
]], float_pos={ ]], float_pos={
[4] = { 1001, "NW", 1, 2, 5, true } [4] = { 1001, "NW", 1, 2, 5, true }
}, win_viewport={ }, win_viewport={
@ -2289,7 +2289,7 @@ describe('float window', function()
{0:~ }{5:}{0: }| {0:~ }{5:}{0: }|
{0:~ }{5:}{1: halloj! }{5:}{0: }| {0:~ }{5:}{1: halloj! }{5:}{0: }|
{0:~ }{5:}{1: BORDAA }{5:}{0: }| {0:~ }{5:}{1: BORDAA }{5:}{0: }|
{0:~ }{5:}🦄BB{5:}{0: }| {0:~ }{5:}{11:🦄BB}{5:}{0: }|
| |
]]} ]]}
end end
@ -2423,10 +2423,10 @@ describe('float window', function()
## grid 3 ## grid 3
| |
## grid 4 ## grid 4
{5:}🦄{7:BB}{5:}| {5:}{11:🦄}{7:BB}{5:}|
{5:}{1: halloj! }{5:}| {5:}{1: halloj! }{5:}|
{5:}{1: BORDAA }{5:}| {5:}{1: BORDAA }{5:}|
{5:}🦄{7:BB}{5:}| {5:}{11:🦄}{7:BB}{5:}|
]], float_pos={ ]], float_pos={
[4] = { 1001, "NW", 1, 2, 5, true } [4] = { 1001, "NW", 1, 2, 5, true }
}, win_viewport={ }, win_viewport={
@ -2437,10 +2437,10 @@ describe('float window', function()
screen:expect{grid=[[ screen:expect{grid=[[
^ | ^ |
{0:~ }| {0:~ }|
{0:~ }{5:}🦄{7:BB}{5:}{0: }| {0:~ }{5:}{11:🦄}{7:BB}{5:}{0: }|
{0:~ }{5:}{1: halloj! }{5:}{0: }| {0:~ }{5:}{1: halloj! }{5:}{0: }|
{0:~ }{5:}{1: BORDAA }{5:}{0: }| {0:~ }{5:}{1: BORDAA }{5:}{0: }|
{0:~ }{5:}🦄{7:BB}{5:}{0: }| {0:~ }{5:}{11:🦄}{7:BB}{5:}{0: }|
| |
]]} ]]}
end end