Dark mode and plug-in with a custom lexer and xml styler

  • Is it possible to support a separate dark mode style, when the plugin uses a custom lexer? See screenshot below of the CSV Lint plug-in in normal and dark mode.


    This plug-in uses a separate CSVLint.xml files for the style but it doesn’t look so nice in dark mode. Btw the custom lexer/styler is talked about in this custom lexer thread.

    If I understand correctly, when I want to update the plugin to support dark mode it basically needs three updates:

    1. Support the new Fluent UI icons, so the plug-in needs to implement the new API NPPM_ADDTOOLBARICON_FORDARKMODE as talked about in this thread. I haven’t looked into it in depth, but it seems feasable.

    2. Windows and panel colors, as mentioned here the plug-in can use the API NPPM_GETEDITORDEFAULTBACKGROUNDCOLOR to get the background color and change the panels and window accordingly. Not the most important issue, but certainly a-nice-to-have.

    3. The custom styling xml, this one I don’t know. I’ve added some test colors to the CSVLint.xml file so that users can un-comment that if they wish to use it. But is it possible to somehow include this as a separate darkmode styling, maybe using a tag? Or is it up to the end-user to set these colors manually when switching between dark mode?

    I couldn’t find any info about that last point 3. Does anyone know if there is a way to supported dark mode in the style.xml?

  • @Bas-de-Reuver ,

    If you look at a couple of examples in Notepad++, you will notice:

    • For built-in lexers, the user needs to select a different theme under Dark Mode compared to Normal Mode – for example, the default.xml theme vs the DarkModeDefault.xml theme. (The Developer had it auto-switch to DarkModeDefault when you change from normal to Dark Mode, but if the user prefers a different dark-ish theme, they have to select it manually.)
    • For UDL, you need to select a separate UDL Language (even if it’s for the same UDL type) for Dark Mode vs Normal Mode – like the supplied markdown._preinstalled.udl.xml vs markdown._preinstalled_DM.udl.xml

    The idea is that a given user won’t necessarily be switching between Dark and Normal modes very frequently; most users will pick whichever they prefer, and stick with it, so there doesn’t need to be much automation.

    Since you are writing this lexer, and since you are providing the CSVLint.xml file, you get to make design decisions for this:

    Do you want to use one CSVLint.xml file that has two sets of color definitions? Maybe <LexerType name="CSVLint" desc="CSV Linter and validator" excluded="no"> vs <LexerType name="CSVLintDark" desc="CSV Linter and validator" excluded="no"> or maybe <LexerType name="CSVLint" mode="Normal" desc="CSV Linter and validator" excluded="no"> vs <LexerType name="CSVLint" mode="Dark" desc="CSV Linter and validator" excluded="no">?

    Or do you want to have two different XML files, like CSVLint.xml and CSVLintDark.xml?

    Or do you want to use StyleID=“0”…“8” for Normal Mode and “10”…“18” for Dark Mode

    It would then be up to you as the lexer plugin’s author, to code the logic to decide which LexerType entry or XML file to look at, depending on the Dark Mode status of Notepad++. Or you could supply a toggle in your lexer plugin’s options to toggle whether its dark mode is on or off.

  • I suppose the simple answer is that users who are using
    a different theme will have to use the style configurator and
    adjust the colors to their needs.
    There is, afaik, no reasonable way for a Lexer plugin to find out
    what colors would fit into the theme currently in use.
    Moreover, a plugin does not receive any notification about theme changes,
    so it is hard to tell when and what should be adjusted.

Log in to reply