Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transparant cursor line turns completely black after using another plugin #68

Open
BdR76 opened this issue May 13, 2023 · 5 comments
Open
Labels
bug Something isn't working

Comments

@BdR76
Copy link
Owner

BdR76 commented May 13, 2023

When the cursor line is set to transparant, it turns completely black after using another plugin making the text at the cursor and selected line unreadable. User has to restart Notepad++ to make it transparant again.

  1. Install both CSV Lint and the Compare Plugin v2
  2. In CSV Lint settings, set Transparent cursor = true
  3. Create two empty files New 1 and New 2
  4. Paste some text for example "1,2,3" in both files
  5. Set one or both to Language > CSVLint
  6. Compare files CTRL + ALT + C
  7. Clear Compare result with CTRL + ALT + X

After the last step the Notepad++ cursor line will be all black, see screenshots below. afaik the error is not due to Compare Plugin v2 but that's just an easy way to trigger this,

csvint_cursor_line

@BdR76 BdR76 added the bug Something isn't working label May 13, 2023
@rdipardo
Copy link
Contributor

afaik the error is not due to Compare Plugin v2

Actually, the whole problem seems to be that comparePlus wipes out the caret line's alpha channel when switching back to the normal view:

https://github.com/pnedev/comparePlus/blob/64a9ee43bbda6755a0cdb784e6b1b3decdb0af6f/src/NppHelpers.cpp#L376-L379

The call to SCI_SETELEMENTCOLOUR only masks the lowest 24 bits of the color value, effectively setting the top 8 "alpha" bits to 0 (transparent). The caret line would disappear, except that this call sends SC_LAYER_BASE to SCI_GETCARETLINELAYER, which tells Scintilla to "[d]raw the selection background opaquely on the base layer".

With CSVLint installed alongside, comparePlus detects the caret line color as 0x66000000, or rbga(0, 0, 0, 0.4) (translucent gray). But what it sends to Scintilla is actually 0x66000000 & 0xFFFFFF, or 0x0 (solid black).

Later, when setting up the compare view, the alpha channel gets put back into the top 8 bits:

https://github.com/pnedev/comparePlus/blob/64a9ee43bbda6755a0cdb784e6b1b3decdb0af6f/src/NppHelpers.cpp#L405-L414

The SCI_SETELEMENT* family of APIs are new to Scintilla 5, so there's definitely no .NET implementation. It could be a problem that CSVLint uses the officially deprecated SCI_SETCARETLINEBACK API1 :

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

A few options to consider:

  1. Adopt the new element style APIs and set the alpha channel the officially supported way; comparePlus already does, reducing the chances of adverse interactions. Only problem is the .NET template needs new infrastructure;

  2. Keep using the old APIs (until Scintilla removes them, at least), but respond to alpha changes and revert the style as needed. It doesn't look like Scintilla provides a notification for changes to the caret line, but you could hook one of Npp's notifications instead; or,

  3. Report the issue to comparePlus, since any plugin that sets the caret line style would be affected. Below is a quick idea of what a third-party fix might look like.

    Note. The alpha value is hard-coded here because it looks better in CVLint's case — the SC_LAYER_UNDER_TEXT flag tends to darken everything by blending the active selection and caret line styles together.

diff --git a/src/NppHelpers.cpp b/src/NppHelpers.cpp
index c8f468b..e46035c 100644
--- a/src/NppHelpers.cpp
+++ b/src/NppHelpers.cpp
@@ -374,11 +374,12 @@ void setNormalView(int view)
 		CallScintilla(view, SCI_SETMARGINSENSITIVEN, MARGIN_NUM, false);

 		const intptr_t caretLineColor = CallScintilla(view, SCI_GETELEMENTCOLOUR, SC_ELEMENT_CARET_LINE_BACK, 0);
+		const intptr_t caretLineColorAlpha = (caretLineColor & 0xFFFFFF) | (0x28 << 24);

 		if (caretLineColor)
-			CallScintilla(view, SCI_SETELEMENTCOLOUR, SC_ELEMENT_CARET_LINE_BACK, caretLineColor & 0xFFFFFF);
+			CallScintilla(view, SCI_SETELEMENTCOLOUR, SC_ELEMENT_CARET_LINE_BACK, caretLineColorAlpha);

-		CallScintilla(view, SCI_SETCARETLINELAYER, SC_LAYER_BASE, 0);
+		CallScintilla(view, SCI_SETCARETLINELAYER, SC_LAYER_UNDER_TEXT, 0);

 		CallScintilla(view, SCI_SETELEMENTCOLOUR, SC_ELEMENT_HIDDEN_LINE, hiddenLinesColor[view]);
 	}

Footnotes

  1. The former APIs support 24-bit BGR colors only, hence their deprecation in favour of the element style APIs.

@molsonkiko
Copy link
Contributor

I'm inclined to try updating this plugin to the new element style APIs and see if that solves the problem with ComparePlus. I'll work on a PR today.

@molsonkiko
Copy link
Contributor

The SCI_SETELEMENT* family of APIs are new to Scintilla 5, so there's definitely no .NET implementation.

Actually they are! See ScintillaGateway.cs.

Unfortunately, it's not as straightforward a fix as I had hoped. Calling editor.SetElementColour(Element.CARET_LINE_BACK, new ColourAlpha(24 << 24)); just results in the caret line being really dark.

@molsonkiko
Copy link
Contributor

molsonkiko commented Jul 15, 2023

The more I think about this, the more I wonder if maybe the easiest "solution" (really patch I suppose) is just to change the default for the Transparent cursor setting.

@BdR76
Copy link
Owner Author

BdR76 commented Jul 19, 2023

As @carlos-esteves pointed out in issue #73 -> When the cursor line is all black after using the Compare plugin, you can open the CSV Lint settings form and then close it to reset the black cursor line back to transparent.

I don't have the time to work on the CSV Lint plug-in at the moment, so this is at least a workaround for now (albeit clunky)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants