BdR76 / CSVLint

CSV Lint plug-in for Notepad++ for syntax highlighting, csv validation, automatic column and datatype detecting, fixed width datasets, change datetime format, decimal separator, sort data, count unique values, convert to xml, json, sql etc. A plugin for data cleaning and working with messy data files.
GNU General Public License v3.0
151 stars 8 forks source link

Transparent cursor line turns completely black when changing style in NPP 8.6 #77

Open CennoxX opened 7 months ago

CennoxX commented 7 months ago

In the new version 8.6 of Notepad++ if I change my style (Settings > Style Configurator … > Select theme), or just open the Select-theme-combobox and cancel, the current line background appears unreadable/black like in #68. Even without opening CSVLint. 1700688326610-ced57241-2c86-4876-95ac-45119097806d-grafik

… until I restart Notepad++, then it’s again as it should be: 1700688292473-2808b868-876b-426b-9859-4ae41bc6853b-grafik

BdR76 commented 7 months ago

You're right I can reproduce this in v8.6, but not in v8.5.3 or v8.5.8. There was a work-around for a similar issue in combination with using the ComparePlugin, but that doesn't seem to work for this issue with the Style Configurator.

Another work-around is to just disable the transparent cursor line for now. You can go to Plugins > CSV Lint > Settings and change the settings TransparentCursor to False.

I suspect it has to do with this fix in Notepad++ I'll have to look into this

dmcmurchy commented 4 months ago

Thanks for commenting about CSV Lint! I had updated it recently and then noticed the background highlighting issue happening and was driving me a little crazy. Note to anyone else that you need to restart Notepad++ after to have the highlighting working as indented.

rdipardo commented 4 months ago

The following can be added to the collection of linked issues, above:

rdipardo commented 4 months ago

Hey, @BdR76, wanna try this?

diff --git a/CSVLintNppPlugin/Main.cs b/CSVLintNppPlugin/Main.cs
index b37a876..fb95ff5 100644
--- a/CSVLintNppPlugin/Main.cs
+++ b/CSVLintNppPlugin/Main.cs
@@ -19,6 +19,8 @@ namespace Kbg.NppPluginNET
     class Main
     {
         internal const string PluginName = "CSV Lint";
+        public static readonly int sCaretLineBackAlpha = 0x18000000;
+        public static readonly int sCaretLineBackAlphaDarkMode = 0x40CCCCCC;
         public static Settings Settings = new Settings();
         public static CultureInfo dummyCulture;

@@ -191,12 +193,17 @@ internal static void RefreshFromSettings()
             if (Settings.TransparentCursor)
             {
                 var editor = new ScintillaGateway(PluginBase.GetCurrentScintilla());
-                if (editor.GetCaretLineBackAlpha() == Alpha.NOALPHA)
+                var rgba = editor.GetElementColour(Element.CARET_LINE_BACK);
+                if (CheckConfigDarkMode() && rgba.Value != sCaretLineBackAlphaDarkMode)
                 {
-                    editor.SetCaretLineBackAlpha((Alpha)16 + 8);
-                    //editor.SetCaretLineBack(sCaretLineBack);
-                    editor.SetCaretLineBack(new Colour(0)); // Main.CheckConfigDarkMode() ? 0xFFFFFF : 0
+                    rgba = new ColourAlpha(sCaretLineBackAlphaDarkMode);
                 }
+                else if (!CheckConfigDarkMode() && rgba.Value != sCaretLineBackAlpha)
+                {
+                    rgba = new ColourAlpha(sCaretLineBackAlpha);
+                }
+                editor.SetElementColour(Element.CARET_LINE_BACK, rgba);
+                editor.SetCaretLineLayer(Layer.UNDER_TEXT); // *IMPORTANT*
             }
         }

The crucial part is sending SCI_SETCARETLINELAYER with SC_LAYER_UNDER_TEXT. Not sure if this will create other conflicts with N++'s default settings, but it seems to be O.K. with the stable 8.6.4 release.

BdR76 commented 4 months ago

Thanks for the suggestion, but using the SetElementColour and SetCaretLineLayer doesn't fix the interference with the ComparePlugin as described in #68

rdipardo commented 4 months ago

[U]sing the SetElementColour and SetCaretLineLayer doesn't fix the interference with the ComparePlugin as described in #68

comparePlus 1.2.0 was supposed to mitigate that issue:

I don't know what more @pnedev can do without compromising his own users' experience.

If it were up to me, I would think about retiring the transparent caret line feature; or at least adding some kludge to disable it whenever comparePlus is installed, e.g.

INotepadPPGateway npp = new NotepadPPGateway();
Settings.TransparentCursor =
    (Directory.GetDirectories(Directory.GetParent(npp.GetPluginConfigPath())?.FullName, "comparePlus")?.Length == 0);
pnedev commented 4 months ago

Hi guys,

I have no idea what more I can do from ComparePlus to make things better. I am no longer supporting the old ComparePlugin so it might (and will) interfere more but in the latest ComparePlus (v1.2 as @rdipardo mentioned) I am storing the color and the layer before modifying them for ComparePlus's needs and after the compare I restore them as they were. Maybe the problem is due to some race condition between plugins - which sets/stores/restores the color settings first, I haven't analyzed the problem thoroughly. If you have any ideas I am open to suggestions.

BR

rdipardo commented 4 months ago

Maybe the problem is due to some race condition between plugins - which sets/stores/restores the color settings first

Let's not forget that Notepad++ finally adopted translucent 32-bit colors in the "Anniversary Edition" (8.6): notepad-plus-plus/notepad-plus-plus@0917875

A good time to drop a plugin feature is when the host application starts providing the same thing natively.

bege10 commented 1 month ago

With Windows 11 the problem with the hidden text only appears when I have set the theme to "Follow Windows". Then both dark and light theme show that issue. When I manually choose light or dark theme the issue is gone. (Switching the theme always shows that issue immediately, but after restarting NPP ist is gone if the setting is dark or light theme.

BdR76 commented 1 month ago

I finally had some time to look at this issue again, bu tI'm still struggling to find a good solution.

@rdipardo A good time to drop a plugin feature is when the host application starts providing the same thing natively.

I've updated Notepad++ to the latest version v8.6.7 including a "refresh" of the stylers.xml file in my %appdata% folder. When I go to the menu item Settings > Style Configuration > Global styles > Caret Colour I can change the R-G-B values for the caret line but not the Alpha/transparency value as far as I can see, also see this thread.

So afaik there is no way to set the caret-line to transparency using just the default Notepad++ functionality, can you confirm that this is correct?

BdR76 commented 1 month ago

@rdipardo So next, I tried changing the code in CSV Lint that sets the transparent cursor line. I've looked at the ComparePlus code see here by @pnedev

However, I'm struggling to get the "new way" to work correctly. I've changed it to this (code below, the hardcoded values are for testing) but then the caret line is not changed at all, the code is executed but the caret line is just the default opaque purple-ish line.

// OLD OLD OLD OLD OLD
/// // set cursor line transparency
/// editor.SetCaretLineBackAlpha((Alpha)16 + 8);
/// //editor.SetCaretLineBack(sCaretLineBack);
/// editor.SetCaretLineBack(new Colour(0)); // Main.CheckConfigDarkMode() ? 0xFFFFFF : 0
/// editor.SetCaretLineLayer(Layer.UNDER_TEXT); // *IMPORTANT*
// OLD OLD OLD OLD OLD

//int safeoldcolor = static_cast<int>(CallScintilla(view, SCI_GETELEMENTCOLOUR, SC_ELEMENT_CARET_LINE_BACK, 0));
int safeoldcolor = 0x808080;

// NEW NEW NEW NEW NEW
// set to transparent
INotepadPPGateway notepad = new NotepadPPGateway();
int hiddenColor = notepad.IsDarkModeEnabled() ? 0xD0D0D0 : 0x202020;

//ColourAlpha clr = new ColourAlpha(hiddenColor | ((int)SciMsg.SC_ALPHA_OPAQUE << 24));
ColourAlpha clr = new ColourAlpha(hiddenColor | (64 << 24));

editor.SetElementColor((int)SciMsg.SC_ELEMENT_HIDDEN_LINE, clr);

editor.SetCaretLineBackAlpha((Alpha)16 + 8);

//const intptr_t alpha = ((100 - caretLineTransp) * SC_ALPHA_OPAQUE / 100);
int alpha = 24;
ColourAlpha newclr = new ColourAlpha( (safeoldcolor & 0xFFFFFF) | (alpha << 24));
editor.SetElementColor((int)SciMsg.SC_ELEMENT_CARET_LINE_BACK, newclr);
editor.SetCaretLineLayer(Layer.UNDER_TEXT);
rdipardo commented 1 month ago

I can't test any code right now since I don't have the .NET 3.5 tools installed (the reason why that's an issue is explained here: https://community.notepad-plus-plus.org/post/93190).

In the meanwhile I would recommend a bit of preventative maintenance: go to the Main class definition and change it to partial class Main; then go to the UnmangaedExports class definition and change it also to partial class Main.

Why? The Main class has tons of static members that need to be initialized as soon as possible (in practice, whenever isUnicode() gets called). Currently it's being deferred until the first time a static Main method gets called, inside the body of UnmangaedExports.setInfo. Waiting that long means risking a null pointer exception (like the ones that probably caused #67, #69, etc.). It's especially important if the caret line background is going to be added to the globally visible shared state...

BdR76 commented 1 month ago

Thanks for the preventative maintenance tip, that sounds like good advice, it might also be the cause of this issue #90

However, when I also change class UnmanagedExports to partial class Main then it crashes at the OK button on the Settings dialog. Like I said I don't have much time to look into the plugin, also I feel like some of the plugin-structure "under the hood" is a bit out of my depth.