nvim-navic icon indicating copy to clipboard operation
nvim-navic copied to clipboard

Bug: When `highlight = true`, does not inherit the background color of the lualine section

Open chrisgrieser opened this issue 1 year ago • 4 comments

When setting highlight = true, the component does not correctly "inherit" the background color of the lualine section it is in, resulting in the highlight backgrounds being off Pasted image 2024-06-10 at 13 03 33@2x

A workaround I found is a rather convoluted function that follows the linked highlights, gets the foreground color, and then sets the background alongside it. A rather convoluted fix:

-- stylua: ignore
local navicHls = { "IconsFile", "IconsModule", "IconsNamespace", "IconsPackage", "IconsClass", "IconsMethod", "IconsProperty", "IconsField", "IconsConstructor", "IconsEnum", "IconsInterface", "IconsFunction", "IconsVariable", "IconsConstant", "IconsString", "IconsNumber", "IconsBoolean", "IconsArray", "IconsObject", "IconsKey", "IconsNull", "IconsEnumMember", "IconsStruct", "IconsEvent", "IconsOperator", "IconsTypeParameter", "Text", "Separator" }
local lualineHl = vim.api.nvim_get_hl(0, { name = "lualine_b_inactive" })
local bg = lualineHl.bg and ("#%06x"):format(lualineHl.bg)
for _, hlName in ipairs(navicHls) do
	hlName = "Navic" .. hlName
	local orgHl = hlName
	local hl
	repeat -- follow linked highlights
		hl = vim.api.nvim_get_hl(0, { name = hlName })
		hlName = hl.link
	until not hl.link
	vim.api.nvim_set_hl(0, orgHl, { fg = hl.fg, bg = bg })
end

the resulting correct look: Pasted image 2024-06-10 at 13 05 23@2x

chrisgrieser avatar Jun 10 '24 11:06 chrisgrieser

+1

iFarmGolems avatar Jun 11 '24 21:06 iFarmGolems

i fixed this by setting WinBar and WinBarNC highlights to the color i needed

renxzen avatar Jun 26 '24 02:06 renxzen

i fixed this by setting WinBar and WinBarNC highlights to the color i needed

If you use the same background color for both, you can't differentiate between the active and inactive window/buffer.

azzamsa avatar Oct 14 '24 01:10 azzamsa

Do any of guys have an idea how i could get this to work, when the background color may change when switching modes?

fabolous005 avatar Dec 08 '24 00:12 fabolous005