SmiteshP / nvim-navic

Simple winbar/statusline plugin that shows your current code context
Apache License 2.0
1.35k stars 49 forks source link

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

Open chrisgrieser opened 3 weeks ago

chrisgrieser commented 3 weeks ago

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

iFarmGolems commented 2 weeks ago

+1

renxzen commented 5 days ago

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