mirror of
https://github.com/neovim/neovim.git
synced 2026-03-30 04:12:01 +00:00
feat(api): nvim_set_hl{update:boolean} #37546
Problem: nvim_set_hl always replaces all attributes. Solution: Add update field. When true, merge with existing attributes instead of replacing. Unspecified attributes are preserved. If highlight group doesn't exist, falls back to reset mode.
This commit is contained in:
@@ -257,6 +257,40 @@ describe('API: set highlight', function()
|
||||
)
|
||||
assert_alive()
|
||||
end)
|
||||
|
||||
it('update=true sets only specified keys', function()
|
||||
api.nvim_set_hl(0, 'TestGroup', { fg = '#ff0000', bg = '#0000ff', bold = true })
|
||||
api.nvim_set_hl(0, 'TestGroup', { bg = '#00ff00', update = true })
|
||||
local hl = api.nvim_get_hl(0, { name = 'TestGroup' })
|
||||
eq(16711680, hl.fg)
|
||||
eq(65280, hl.bg)
|
||||
eq(true, hl.bold)
|
||||
|
||||
api.nvim_set_hl(0, 'TestGroup', { bold = false, update = true })
|
||||
hl = api.nvim_get_hl(0, { name = 'TestGroup' })
|
||||
eq(nil, hl.bold)
|
||||
eq(16711680, hl.fg)
|
||||
|
||||
api.nvim_set_hl(0, 'TestGroup', { italic = true })
|
||||
|
||||
hl = api.nvim_get_hl(0, { name = 'TestGroup' })
|
||||
eq(nil, hl.fg)
|
||||
eq(nil, hl.bg)
|
||||
eq(true, hl.italic)
|
||||
|
||||
local ns = api.nvim_create_namespace('test')
|
||||
api.nvim_set_hl(ns, 'TestGroup', { fg = '#ff0000', italic = true })
|
||||
api.nvim_set_hl(ns, 'TestGroup', { fg = '#00ff00', update = true })
|
||||
hl = api.nvim_get_hl(ns, { name = 'TestGroup' })
|
||||
eq(65280, hl.fg)
|
||||
eq(true, hl.italic)
|
||||
|
||||
api.nvim_set_hl(0, 'LinkedGroup', { link = 'Normal' })
|
||||
api.nvim_set_hl(0, 'LinkedGroup', { bold = true, update = true })
|
||||
hl = api.nvim_get_hl(0, { name = 'LinkedGroup' })
|
||||
eq(nil, hl.link)
|
||||
eq(true, hl.bold)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('API: get highlight', function()
|
||||
|
||||
Reference in New Issue
Block a user