mirror of
https://github.com/neovim/neovim.git
synced 2026-04-25 08:44:06 +00:00
fix(api): nvim_set_hl boolean false corrupts underline styles (#38504)
Problem: setting one underline style to false clears bits belonging
to another style. `{underdouble = true, underdashed = false}` results
in undercurl because CHECK_FLAG_WITH_KEY does `m &= ~flag` which
doesn't work for multi-bit encoded values sharing HL_UNDERLINE_MASK.
Solution: use a local variable to derive the correct clear mask from
the flag. Clear the whole HL_UNDERLINE_MASK field instead of individual
bits, and only clear on false when the current style actually matches.
This commit is contained in:
@@ -290,6 +290,39 @@ describe('API: set highlight', function()
|
||||
hl = api.nvim_get_hl(0, { name = 'LinkedGroup' })
|
||||
eq(nil, hl.link)
|
||||
eq(true, hl.bold)
|
||||
|
||||
-- underline style flags: false must not corrupt other styles
|
||||
local unders = { 'underline', 'undercurl', 'underdouble', 'underdotted', 'underdashed' }
|
||||
for _, a in ipairs(unders) do
|
||||
for _, b in ipairs(unders) do
|
||||
if a ~= b then
|
||||
api.nvim_set_hl(0, 'TestGroup', { [a] = true, [b] = false })
|
||||
hl = api.nvim_get_hl(0, { name = 'TestGroup' })
|
||||
eq(true, hl[a])
|
||||
eq(nil, hl[b])
|
||||
end
|
||||
end
|
||||
end
|
||||
api.nvim_set_hl(0, 'TestGroup', { underdouble = true, fg = '#ff0000', bold = true })
|
||||
api.nvim_set_hl(0, 'TestGroup', { fg = '#00ff00', update = true })
|
||||
hl = api.nvim_get_hl(0, { name = 'TestGroup' })
|
||||
eq(true, hl.underdouble)
|
||||
eq(true, hl.bold)
|
||||
eq(65280, hl.fg)
|
||||
|
||||
api.nvim_set_hl(0, 'TestGroup', { underdashed = true, update = true })
|
||||
hl = api.nvim_get_hl(0, { name = 'TestGroup' })
|
||||
eq(true, hl.underdashed)
|
||||
eq(nil, hl.underdouble)
|
||||
|
||||
api.nvim_set_hl(0, 'TestGroup', { underdouble = true, bold = true })
|
||||
api.nvim_set_hl(0, 'TestGroup', { underdashed = false, update = true })
|
||||
hl = api.nvim_get_hl(0, { name = 'TestGroup' })
|
||||
eq(true, hl.underdouble)
|
||||
api.nvim_set_hl(0, 'TestGroup', { underdouble = false, update = true })
|
||||
hl = api.nvim_get_hl(0, { name = 'TestGroup' })
|
||||
eq(nil, hl.underdouble)
|
||||
eq(true, hl.bold)
|
||||
end)
|
||||
end)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user