SmiteshP / nvim-navic

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

fix: differently colored trailing cell in navic element #137

Closed kmoschcau closed 7 months ago

kmoschcau commented 8 months ago

This fixes an issue where a single, differently colored cell is showing up in the status line.

I was having this problem that when I set up the highlights of navic to match those of my lualine, I got this: image

After some searching I found out that this is caused by a trailing highlight reset (%*), which then causes the following padding added by lualine to be colored differently. When I disabled the right-side padding in my lualine config for this element, the problem also went away. So I figured you are not supposed to reset the final highlight of your lualine element. Thus this change simply removes the last highlight reset from the formatted element string.

SmiteshP commented 7 months ago

The trailing symbols are meant to finish off the highlight section. I think it is hygienic to keep navic's highlights to its own section. Any section that comes after it should defined its highlights on its own, even if it if padding element.

kmoschcau commented 7 months ago

But how am I supposed to remove this cell then? You will always get this if your statusline background uses a different color than the Normal highlight group. The only other option that remains is to not have padding, which doesn't seem great to me either.

Edit: OK I think I see the problem now. Lualine with its padding does not expect a highlight reset, but if you use it in other ways it would be prudent to use a highlight reset.

Edit2: Not even overriding the color for the navic element in lualine works. Only removing the right side padding works. But yeah I'll just leave it at that. At this point the only other thing I could think of, is for navic to somehow detect it's being used in an environment where the reset is not needed and just not apply it in that case.

kmoschcau commented 7 months ago

For anyone else stumbling across this in the future, I ended up solving it with a lualine component like this:

{
  "navic",
  fmt = function(text)
    return string.gsub(text, "%%%*$", "")
  end,
}