feat(ui): statusline text inherits highlights #29976

Changes apply to the winbar, statusline, and tabline text.
This commit is contained in:
Riley Bruins 2024-10-12 10:57:31 -07:00 committed by GitHub
parent 4b90952851
commit e049c6e4c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 74 additions and 10 deletions

View File

@ -262,6 +262,10 @@ These existing features changed their behavior.
more emoji characters than before, including those encoded with multiple more emoji characters than before, including those encoded with multiple
emoji codepoints combined with ZWJ (zero width joiner) codepoints. emoji codepoints combined with ZWJ (zero width joiner) codepoints.
• Text in the 'statusline', 'tabline', and 'winbar' now inherits highlights
from the respective |hl-StatusLine|, |hl-TabLine|, and |hl-WinBar| highlight
groups.
• |vim.on_key()| callbacks won't be invoked recursively when a callback itself • |vim.on_key()| callbacks won't be invoked recursively when a callback itself
consumes input. consumes input.

View File

@ -430,7 +430,7 @@ static void win_redr_custom(win_T *wp, bool draw_winbar, bool draw_ruler)
if (hltab[n].userhl == 0) { if (hltab[n].userhl == 0) {
curattr = attr; curattr = attr;
} else if (hltab[n].userhl < 0) { } else if (hltab[n].userhl < 0) {
curattr = syn_id2attr(-hltab[n].userhl); curattr = hl_combine_attr(attr, syn_id2attr(-hltab[n].userhl));
} else if (wp != NULL && wp != curwin && wp->w_status_height != 0) { } else if (wp != NULL && wp != curwin && wp->w_status_height != 0) {
curattr = highlight_stlnc[hltab[n].userhl - 1]; curattr = highlight_stlnc[hltab[n].userhl - 1];
} else { } else {

View File

@ -1691,6 +1691,7 @@ describe("'winhighlight' highlight", function()
[29] = { foreground = Screen.colors.Blue1, background = Screen.colors.Red, bold = true }, [29] = { foreground = Screen.colors.Blue1, background = Screen.colors.Red, bold = true },
[30] = { background = tonumber('0xff8800') }, [30] = { background = tonumber('0xff8800') },
[31] = { background = tonumber('0xff8800'), bold = true, foreground = Screen.colors.Blue }, [31] = { background = tonumber('0xff8800'), bold = true, foreground = Screen.colors.Blue },
[32] = { bold = true, reverse = true, background = Screen.colors.DarkGreen },
} }
command('hi Background1 guibg=DarkBlue') command('hi Background1 guibg=DarkBlue')
command('hi Background2 guibg=DarkGreen') command('hi Background2 guibg=DarkGreen')
@ -2253,10 +2254,10 @@ describe("'winhighlight' highlight", function()
some text | some text |
more tex^t | more tex^t |
{0:~ }| {0:~ }|
{3:[No Name] }{1:2,9 All}| {3:[No Name] }{11:2,9 All}|
some text | some text |
more text | more text |
{4:[No Name] }{1:1,1 All}| {4:[No Name] }{14:1,1 All}|
| |
]], ]],
} }
@ -2267,10 +2268,10 @@ describe("'winhighlight' highlight", function()
some text | some text |
more tex^t | more tex^t |
{0:~ }| {0:~ }|
{3:[No Name] }{5:2,9 All}| {3:[No Name] }{32:2,9 All}|
some text | some text |
more text | more text |
{4:[No Name] }{1:1,1 All}| {4:[No Name] }{14:1,1 All}|
| |
]], ]],
} }
@ -2281,10 +2282,10 @@ describe("'winhighlight' highlight", function()
some tex^t | some tex^t |
more text | more text |
{0:~ }| {0:~ }|
{3:[No Name] }{5:1,9 All}| {3:[No Name] }{32:1,9 All}|
some text | some text |
more text | more text |
{4:[No Name] }{1:1,1 All}| {4:[No Name] }{14:1,1 All}|
| |
]], ]],
} }

View File

@ -474,26 +474,42 @@ describe('multibyte rendering: statusline', function()
end) end)
it('emoji with ZWJ in filename with custom stl', function() it('emoji with ZWJ in filename with custom stl', function()
screen:add_extra_attr_ids {
[100] = {
bold = true,
reverse = true,
foreground = Screen.colors.Gray100,
background = Screen.colors.Red,
},
}
command('set statusline=xx%#ErrorMsg#%f%##yy') command('set statusline=xx%#ErrorMsg#%f%##yy')
command('file 🧑‍💻') command('file 🧑‍💻')
screen:expect { screen:expect {
grid = [[ grid = [[
^ | ^ |
{1:~ }| {1:~ }|
{3:xx}{9:🧑💻}{3:yy }| {3:xx}{100:🧑💻}{3:yy }|
| |
]], ]],
} }
end) end)
it('unprintable chars in filename with custom stl', function() it('unprintable chars in filename with custom stl', function()
screen:add_extra_attr_ids {
[100] = {
bold = true,
reverse = true,
foreground = Screen.colors.Gray100,
background = Screen.colors.Red,
},
}
command('set statusline=xx%#ErrorMsg#%f%##yy') command('set statusline=xx%#ErrorMsg#%f%##yy')
command('file 🧑​💻') command('file 🧑​💻')
screen:expect { screen:expect {
grid = [[ grid = [[
^ | ^ |
{1:~ }| {1:~ }|
{3:xx}{9:🧑<200b>💻}{3:yy }| {3:xx}{100:🧑<200b>💻}{3:yy }|
| |
]], ]],
} }

View File

@ -27,6 +27,7 @@ for _, model in ipairs(mousemodels) do
screen:set_default_attr_ids({ screen:set_default_attr_ids({
[0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText [0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText
[1] = { bold = true, reverse = true }, -- StatusLine [1] = { bold = true, reverse = true }, -- StatusLine
[2] = { bold = true, foreground = Screen.colors.Blue, reverse = true }, -- NonText combined with StatusLine
}) })
screen:attach() screen:attach()
command('set laststatus=2 mousemodel=' .. model) command('set laststatus=2 mousemodel=' .. model)
@ -87,7 +88,7 @@ for _, model in ipairs(mousemodels) do
grid = [[ grid = [[
^ | ^ |
{0:~ }|*5 {0:~ }|*5
{1:^I}{0:^A^I^A^I}{1:^A }| {1:^I}{2:^A^I^A^I}{1:^A }|
| |
]], ]],
} }

View File

@ -125,6 +125,26 @@ describe('tabline', function()
} }
end) end)
it('combines highlight attributes', function()
screen:set_default_attr_ids({
[1] = { foreground = Screen.colors.Blue1, bold = true }, -- StatusLine
[2] = { bold = true, italic = true }, -- StatusLine
[3] = { bold = true, italic = true, foreground = Screen.colors.Red }, -- NonText combined with StatusLine
})
command('hi TabLineFill gui=bold,italic')
command('hi Identifier guifg=red')
command('set tabline=Test%#Identifier#here')
command('set showtabline=2')
screen:expect {
grid = [[
{2:Test}{3:here }|
^ |
{1:~ }|*2
|
]],
}
end)
it('click definitions do not leak memory #21765', function() it('click definitions do not leak memory #21765', function()
command('set tabline=%@MyClickFunc@MyClickText%T') command('set tabline=%@MyClickFunc@MyClickText%T')
command('set showtabline=2') command('set showtabline=2')

View File

@ -40,6 +40,16 @@ describe('winbar', function()
bold = true, bold = true,
foreground = Screen.colors.Magenta, foreground = Screen.colors.Magenta,
}, },
[12] = {
underline = true,
background = Screen.colors.Red,
},
[13] = {
underline = true,
bold = true,
foreground = Screen.colors.Blue,
background = Screen.colors.Red,
},
}) })
api.nvim_set_option_value('winbar', 'Set Up The Bars', {}) api.nvim_set_option_value('winbar', 'Set Up The Bars', {})
end) end)
@ -182,6 +192,18 @@ describe('winbar', function()
]]) ]])
end) end)
it('works with combined highlight attributes', function()
command('hi Winbar guibg=red gui=underline')
command('hi Identifier guifg=blue gui=bold')
command('set winbar=Lookatmy%#Identifier#highlights')
screen:expect([[
{12:Lookatmy}{13:highlights }|
^ |
{3:~ }|*10
|
]])
end)
it('can be ruler', function() it('can be ruler', function()
insert [[ insert [[
just some just some