mawkler / modicator.nvim

Cursor line number mode indicator plugin for Neovim
MIT License
298 stars 6 forks source link

Line number colours don’t change after changing theme on the fly #8

Closed ddbrierton closed 1 year ago

ddbrierton commented 1 year ago

Hi, first off thank you for this great little plugin. It does one thing simply and elegantly and I find it very useful.

I’m not sure if my issue is a bug or a feature request. I have two favourite themes (ayu-dark Shatur/neovim-ayu and kanagawa-dragon rebelot/kanagawa.nvim) that I switch between depending on my mood. Both themes allow you to create custom groups in their overrides, and so I define my styles for Modicator and Alpha’s dashboard like so:

        overrides = function(colors) -- add/modify highlights
          return {
            ModicatorNormal = { fg = colors.theme.syn.fun },
            ModicatorInsert = { fg = colors.theme.diag.ok },
            ModicatorVisual = { fg = colors.theme.syn.keyword },
            ModicatorReplace = { fg = colors.theme.syn.constant },
            ModicatorCommand = { fg = colors.theme.syn.operator },
            AlphaDashboardHeader = { fg = colors.palette.carpYellow, bold = true },
            AlphaDashboardButton = { fg = colors.palette.waveRed },
            AlphaDashboardFooter = { fg = colors.palette.springBlue },
          }

and in my Modicator config I have this:

    modicator.setup({
      show_warnings = true,
      highlights = {
        defaults = {
          foreground = modicator.get_highlight_fg("CursorLineNr"),
          background = modicator.get_highlight_bg("CursorLineNr"),
          bold = true,
          italic = false,
        },
        modes = {
          ["n"] = {
            foreground = modicator.get_highlight_fg("ModicatorNormal"),
          },
          ["i"] = {
            foreground = modicator.get_highlight_fg("ModicatorInsert"),
          },
          ["v"] = {
            foreground = modicator.get_highlight_fg("ModicatorVisual"),
          },
          ["V"] = {
            foreground = modicator.get_highlight_fg("ModicatorVisual"),
          },
          [""] = { -- This symbol is the ^V character
            foreground = modicator.get_highlight_fg("ModicatorVisual"),
          },
          ["s"] = {
            foreground = modicator.get_highlight_fg("ModicatorVisual"),
          },
          ["S"] = {
            foreground = modicator.get_highlight_fg("ModicatorVisual"),
          },
          ["R"] = {
            foreground = modicator.get_highlight_fg("ModicatorReplace"),
          },
          ["c"] = {
            foreground = modicator.get_highlight_fg("ModicatorCommand"),
          },
        },
      },

This works great if I change the default theme by commenting and uncommenting the relevant lines below and restart nvim:

  {
    "LazyVim/LazyVim",
    opts = {
      colorscheme = "ayu-dark”,
     -- colorscheme = “kanagawa-dragon”,
    },
  },

However, if I just change colorscheme on the fly with e.g. :colorscheme kanagawa-dragon then the line numbers remain in the previous scheme’s colours.

Screenshot 2023-05-19 at 10 11 39

I’m not sure why this is happening. Alpha’s dashboard, whose colours are set in a similar way, changes just fine when I do this. What is the intended behaviour?

Is this something your plugin should take care of, or is it up to me to add an autocmd for the ColorScheme event? If the latter, what exactly do I need to run, Modicator’s setup function again?

Thanks again.

mawkler commented 1 year ago

@ddbrierton Thank you for reporting this. It sounds like a bug and I think it's because the highlights are calculated and set once, on startup. I think the solution is to change modicator to dynamically use the colors from a highlight group for each mode (Normal, Visual, Insert, etc.). That way you can specify what the highlights should be for each colorscheme, and the modicator's colors would change whenever the colorscheme changes 🙂

textzenith commented 1 year ago

Came here to post this.

I think the solution is to change modicator to dynamically use the colors from a highlight group for each mode (Normal, Visual, Insert, etc.).

Would be a nice default! 😀

ddbrierton commented 1 year ago

Thanks! Works perfectly.