Skip to content

Commit 562d118

Browse files
glepnirhuangyingw
authored andcommitted
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.
1 parent 5906255 commit 562d118

File tree

5 files changed

+27
-22
lines changed

5 files changed

+27
-22
lines changed

runtime/doc/api.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3259,13 +3259,15 @@ nvim_open_win({buffer}, {enter}, {config}) *nvim_open_win()*
32593259
<
32603260
• title: Title (optional) in window border, string or list.
32613261
List should consist of `[text, highlight]` tuples. If
3262-
string, the default highlight group is `FloatTitle`.
3262+
string, or a tuple lacks a highlight, the default
3263+
highlight group is `FloatTitle`.
32633264
• title_pos: Title position. Must be set with `title`
32643265
option. Value can be one of "left", "center", or "right".
32653266
Default is `"left"`.
32663267
• footer: Footer (optional) in window border, string or
32673268
list. List should consist of `[text, highlight]` tuples.
3268-
If string, the default highlight group is `FloatFooter`.
3269+
If string, or a tuple lacks a highlight, the default
3270+
highlight group is `FloatFooter`.
32693271
• footer_pos: Footer position. Must be set with `footer`
32703272
option. Value can be one of "left", "center", or "right".
32713273
Default is `"left"`.

runtime/lua/vim/_meta/api.lua

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/nvim/api/win_config.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,13 @@
189189
/// ```
190190
/// - title: Title (optional) in window border, string or list.
191191
/// List should consist of `[text, highlight]` tuples.
192-
/// If string, the default highlight group is `FloatTitle`.
192+
/// If string, or a tuple lacks a highlight, the default highlight group is `FloatTitle`.
193193
/// - title_pos: Title position. Must be set with `title` option.
194194
/// Value can be one of "left", "center", or "right".
195195
/// Default is `"left"`.
196196
/// - footer: Footer (optional) in window border, string or list.
197197
/// List should consist of `[text, highlight]` tuples.
198-
/// If string, the default highlight group is `FloatFooter`.
198+
/// If string, or a tuple lacks a highlight, the default highlight group is `FloatFooter`.
199199
/// - footer_pos: Footer position. Must be set with `footer` option.
200200
/// Value can be one of "left", "center", or "right".
201201
/// Default is `"left"`.
@@ -851,7 +851,6 @@ static void parse_bordertext(Object bordertext, BorderTextType bordertext_type,
851851
bool *is_present;
852852
VirtText *chunks;
853853
int *width;
854-
int default_hl_id;
855854
switch (bordertext_type) {
856855
case kBorderTextTitle:
857856
if (fconfig->title) {
@@ -861,7 +860,6 @@ static void parse_bordertext(Object bordertext, BorderTextType bordertext_type,
861860
is_present = &fconfig->title;
862861
chunks = &fconfig->title_chunks;
863862
width = &fconfig->title_width;
864-
default_hl_id = syn_check_group(S_LEN("FloatTitle"));
865863
break;
866864
case kBorderTextFooter:
867865
if (fconfig->footer) {
@@ -871,7 +869,6 @@ static void parse_bordertext(Object bordertext, BorderTextType bordertext_type,
871869
is_present = &fconfig->footer;
872870
chunks = &fconfig->footer_chunks;
873871
width = &fconfig->footer_width;
874-
default_hl_id = syn_check_group(S_LEN("FloatFooter"));
875872
break;
876873
}
877874

@@ -881,7 +878,7 @@ static void parse_bordertext(Object bordertext, BorderTextType bordertext_type,
881878
return;
882879
}
883880
kv_push(*chunks, ((VirtTextChunk){ .text = xstrdup(bordertext.data.string.data),
884-
.hl_id = default_hl_id }));
881+
.hl_id = -1 }));
885882
*width = (int)mb_string2cells(bordertext.data.string.data);
886883
*is_present = true;
887884
return;

src/nvim/drawscreen.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#include "nvim/autocmd.h"
6666
#include "nvim/autocmd_defs.h"
6767
#include "nvim/buffer.h"
68+
#include "nvim/buffer_defs.h"
6869
#include "nvim/charset.h"
6970
#include "nvim/cmdexpand.h"
7071
#include "nvim/cursor.h"
@@ -715,14 +716,17 @@ void end_search_hl(void)
715716
screen_search_hl.rm.regprog = NULL;
716717
}
717718

718-
static void win_redr_bordertext(win_T *wp, VirtText vt, int col)
719+
static void win_redr_bordertext(win_T *wp, VirtText vt, int col, BorderTextType bt)
719720
{
720721
for (size_t i = 0; i < kv_size(vt);) {
721-
int attr = 0;
722+
int attr = -1;
722723
char *text = next_virt_text_chunk(vt, &i, &attr);
723724
if (text == NULL) {
724725
break;
725726
}
727+
if (attr == -1) { // No highlight specified.
728+
attr = wp->w_ns_hl_attr[bt == kBorderTextTitle ? HLF_BTITLE : HLF_BFOOTER];
729+
}
726730
attr = hl_apply_winblend(wp, attr);
727731
col += grid_line_puts(col, text, -1, attr);
728732
}
@@ -773,7 +777,7 @@ static void win_redr_border(win_T *wp)
773777
if (wp->w_config.title) {
774778
int title_col = win_get_bordertext_col(icol, wp->w_config.title_width,
775779
wp->w_config.title_pos);
776-
win_redr_bordertext(wp, wp->w_config.title_chunks, title_col);
780+
win_redr_bordertext(wp, wp->w_config.title_chunks, title_col, kBorderTextTitle);
777781
}
778782
if (adj[1]) {
779783
grid_line_put_schar(icol + adj[3], chars[2], attrs[2]);
@@ -809,7 +813,7 @@ static void win_redr_border(win_T *wp)
809813
if (wp->w_config.footer) {
810814
int footer_col = win_get_bordertext_col(icol, wp->w_config.footer_width,
811815
wp->w_config.footer_pos);
812-
win_redr_bordertext(wp, wp->w_config.footer_chunks, footer_col);
816+
win_redr_bordertext(wp, wp->w_config.footer_chunks, footer_col, kBorderTextFooter);
813817
}
814818
if (adj[1]) {
815819
grid_line_put_schar(icol + adj[3], chars[4], attrs[4]);

test/functional/ui/float_spec.lua

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2127,7 +2127,7 @@ describe('float window', function()
21272127
## grid 3
21282128
|
21292129
## grid 4
2130-
{5:╔═════}🦄BB{5:╗}|
2130+
{5:╔═════}{11:🦄BB}{5:╗}|
21312131
{5:║}{1: halloj! }{5:║}|
21322132
{5:║}{1: BORDAA }{5:║}|
21332133
{5:╚═════════╝}|
@@ -2141,7 +2141,7 @@ describe('float window', function()
21412141
screen:expect{grid=[[
21422142
^ |
21432143
{0:~ }|
2144-
{0:~ }{5:╔═════}🦄BB{5:╗}{0: }|
2144+
{0:~ }{5:╔═════}{11:🦄BB}{5:╗}{0: }|
21452145
{0:~ }{5:║}{1: halloj! }{5:║}{0: }|
21462146
{0:~ }{5:║}{1: BORDAA }{5:║}{0: }|
21472147
{0:~ }{5:╚═════════╝}{0: }|
@@ -2275,7 +2275,7 @@ describe('float window', function()
22752275
{5:╔═════════╗}|
22762276
{5:║}{1: halloj! }{5:║}|
22772277
{5:║}{1: BORDAA }{5:║}|
2278-
{5:╚═════}🦄BB{5:╝}|
2278+
{5:╚═════}{11:🦄BB}{5:╝}|
22792279
]], float_pos={
22802280
[4] = { 1001, "NW", 1, 2, 5, true }
22812281
}, win_viewport={
@@ -2289,7 +2289,7 @@ describe('float window', function()
22892289
{0:~ }{5:╔═════════╗}{0: }|
22902290
{0:~ }{5:║}{1: halloj! }{5:║}{0: }|
22912291
{0:~ }{5:║}{1: BORDAA }{5:║}{0: }|
2292-
{0:~ }{5:╚═════}🦄BB{5:╝}{0: }|
2292+
{0:~ }{5:╚═════}{11:🦄BB}{5:╝}{0: }|
22932293
|
22942294
]]}
22952295
end
@@ -2423,10 +2423,10 @@ describe('float window', function()
24232423
## grid 3
24242424
|
24252425
## grid 4
2426-
{5:╔═════}🦄{7:BB}{5:╗}|
2426+
{5:╔═════}{11:🦄}{7:BB}{5:╗}|
24272427
{5:║}{1: halloj! }{5:║}|
24282428
{5:║}{1: BORDAA }{5:║}|
2429-
{5:╚═════}🦄{7:BB}{5:╝}|
2429+
{5:╚═════}{11:🦄}{7:BB}{5:╝}|
24302430
]], float_pos={
24312431
[4] = { 1001, "NW", 1, 2, 5, true }
24322432
}, win_viewport={
@@ -2437,10 +2437,10 @@ describe('float window', function()
24372437
screen:expect{grid=[[
24382438
^ |
24392439
{0:~ }|
2440-
{0:~ }{5:╔═════}🦄{7:BB}{5:╗}{0: }|
2440+
{0:~ }{5:╔═════}{11:🦄}{7:BB}{5:╗}{0: }|
24412441
{0:~ }{5:║}{1: halloj! }{5:║}{0: }|
24422442
{0:~ }{5:║}{1: BORDAA }{5:║}{0: }|
2443-
{0:~ }{5:╚═════}🦄{7:BB}{5:╝}{0: }|
2443+
{0:~ }{5:╚═════}{11:🦄}{7:BB}{5:╝}{0: }|
24442444
|
24452445
]]}
24462446
end

0 commit comments

Comments
 (0)