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

Notepad++ v8.4 and beyond (inclusive 8.4.2) CRASHES or doesn't work properly when applying a color on selected text using NppExec. #69

Closed
jabal1 opened this issue Jun 23, 2022 · 9 comments

Comments

@jabal1
Copy link

jabal1 commented Jun 23, 2022

Notepad++ v8.4 and beyond (inclusive 8.4.2) CRASHES or doesn't work properly when applying a color on selected text using NppExec.

In notepad++v8.3.3 everything works fine but when I wanted to upgrade to notepad++v8.4 and beyond Notepad++ went unstable and did not work as usual.

I always use two views, meaning I have text files open on two columns.
I want to have my selected text to be "GREEN on BLACK", therefore I have implemented NppExec with following script :

SCI_SENDMSG 2067 1 65280

This sets globally the foreground color to green fro selected text.
Although this initialization only works for one of the views (the active one at startup time) when I start notepad++, thus I always have also to apply it manually on the second view which does not have the focus at startup.

Now this worked perfectly well in v8.3.3 where I could have both views with selected text displayed "GREEN on BLACK".

But when I updated to v8.4 or beyond this did not work anymore.
I still had to execute the second NppExec command manually on the second view, but each time I lose the focus on one view the selected text returns to the default higlighting and more problematic notepad++ now very often just CRASHES when doing so !

Steps to Reproduce the Issue

  1. NppExec must be present
  2. define a NppEXEC script used at startup containing--> SCI_SENDMSG 2067 1 65280
  3. open notepad++having already 2 views with files open
  4. execute manually the NppEexec script on the second view which had not the focus when notepad++was launched
  5. change alternatively the focus from one view to another, when the focus leaves the view the corresponding selected text highlighting reverts to default ! Or even worse notepad++ simply CRASHES !

Expected Behavior

As in v8.3.3 I expect the selected text to remain highlighted in both views in "GREEN on BLACK", and more importantly notepad++ should not CRASH as this happens very frequently with v8.4 and beyond !

Actual Behavior

With v8.4 and beyond changing the focus to one view reverts the other view to the default highlighting for selected text, and it makes notepad++ CRASH very frequently.

In fact it CRASHES so often I had to reinstall v8.3.3 !

Debug Information

NppExec script
image

WORKING VERSION
Notepad++ v8.3.3 (64-bit)
Build time : Mar 13 2022 - 17:20:02
Path : C:\Program Files\Notepad++\notepad++.exe
Command Line :
Admin mode : OFF
Local Conf mode : OFF
Cloud Config : OFF
OS Name : Windows 10 Enterprise (64-bit)
OS Version : 2009
OS Build : 19044.1706
Current ANSI codepage : 1252
Plugins : DSpellCheck.dll mimeTools.dll NppConverter.dll NppExec.dll NppExport.dll NppHorizontalRuler.dll

image

PROBLEMATIC VERSION
Notepad++ v8.4 (64-bit)
Build time : Apr 20 2022 - 03:31:06
Path : C:\Program Files\Notepad++\notepad++.exe
Command Line :
Admin mode : OFF
Local Conf mode : OFF
Cloud Config : OFF
OS Name : Windows 10 Enterprise (64-bit)
OS Version : 2009
OS Build : 19044.1706
Current ANSI codepage : 1252
Plugins : DSpellCheck.dll mimeTools.dll NppConverter.dll NppExec.dll NppExport.dll NppHorizontalRuler.dll

image

Unfortunately even with the latest version of NppExec it does not work, maybe it crashes a bit less often but that's it, when losing the focus it still reverts to the default highlighting instead of applying the one from the script.

image

@d0vgan
Copy link
Owner

d0vgan commented Jun 23, 2022

Thank you for this detailed bug report!
Notepad++ uses an updated version of Scintilla starting from Notepad++ 8.4. It also affected the plugins that were not recently updated:
https://community.notepad-plus-plus.org/topic/23079/eventual-bugs-in-plugins-with-notepad-v8-4-x
This may explain why 8.3.3 is still OK.
I tried the same script

sci_sendmsg SCI_SETSELFORE 1 65280

and it everything works for me for both 64-bit and 32-bit Notepad++ 8.4.2.
I noticed you are using a couple of custom plugins: DSpellCheck.dll and NppHorizontalRuler.dll.
Could you try temporary remove both of them and try to reproduce the issue?
If the issue will go away, then you could try to restore one of them to identify which one causes the issue to re-appear.

@rdipardo
Copy link
Contributor

The crash is caused by NppHorizontalRuler, assuming it was compiled from this source tree.

It uses the length returned by SCI_GETCURLINE without adding 1, a necessary correction since Scintilla 5.1.5 shortened the return value of that API.

src/HorizontalRuler.cpp:379:    nLineLength = (int)SendMessage(this->scintillaHwnd, SCI_GETCURLINE, 0, 0);
src/HorizontalRuler.cpp:381:    nCaret = (int)SendMessage(this->scintillaHwnd, SCI_GETCURLINE, nLineLength, (LPARAM)curLin);

The developer of NppHorizontalRuler should be notfied with a link to notepad-plus-plus/notepad-plus-plus#11766

@jabal1
Copy link
Author

jabal1 commented Jun 24, 2022

Hello,

@d0vgan

As suggested by @rdipardo on the bug report of notepad++ I tried a recent development build with only the NppExec plugin installed and no other plugin and it still didn't work as expected.

So when you say "everything works for me for both 64-bit and 32-bit Notepad++ 8.4.2" are you sure that you have at the same time the highlighting of selected text in both tabs like in version 8.3.3 ?

image

@d0vgan
Copy link
Owner

d0vgan commented Jun 24, 2022

Only the active view has the selected text in green: i.e. when the primary view is active, its selected text foreground color is green; when the secondary view is active, its selected text foreground color is green.
I believe that starting from Notepad++ 8.4 there are two different options for the foreground color: one for the active foreground color (when the view is active, the one set by SCI_SETSELFORE) and another one for the inactive foreground color (when the view is inactive).
Looking at the Scintilla documentation, probably SCI_SETELEMENTCOLOUR should be used instead of SCI_SETSELFORE.
https://www.scintilla.org/ScintillaDoc.html
Frankly, I'd appreciate if ScintillaDoc mentioned that explicitly (e.g. if there was a clear statement such as "the SCI_SETSELFORE is obsolete; use SCI_SETELEMENTCOLOUR instead").

@d0vgan
Copy link
Owner

d0vgan commented Jun 24, 2022

@jabal1
Copy link
Author

jabal1 commented Jun 24, 2022

Well I tried this in Notepad++ 8.4.2 with NppExec 0.8.2 :

SCI_SENDMSG SCI_SETELEMENTCOLOUR 1 65280

And unfortunately it does not work,

SCI_SETSELFORE 1 65280 works the same way as SCI_SENDMSG 2067 1 65280

But SCI_SETELEMENTCOLOUR does not seem to work at all in the intended way.

@d0vgan
Copy link
Owner

d0vgan commented Jun 24, 2022

This works:

sci_sendmsg SCI_SETELEMENTCOLOUR SC_ELEMENT_SELECTION_TEXT 65280
sci_sendmsg SCI_SETELEMENTCOLOUR SC_ELEMENT_SELECTION_INACTIVE_TEXT 65280

@rdipardo
Copy link
Contributor

This works:

sci_sendmsg SCI_SETELEMENTCOLOUR SC_ELEMENT_SELECTION_TEXT 65280
sci_sendmsg SCI_SETELEMENTCOLOUR SC_ELEMENT_SELECTION_INACTIVE_TEXT 65280

There is one catch — you must turn off DirectWrite:

nppExec-D2D

The new APIs were designed to support alpha channels. The officially correct usage is:

SC_ELEMENT_SELECTION_INACTIVE_TEXT : colouralpha
SC_ELEMENT_SELECTION_INACTIVE_BACK : colouralpha

With colouralpha being specifically a 32-bit value:

Colours are set using the RGBA format (Red, Green, Blue, Alpha). This is similar to colour but with a byte of alpha added. They are combined as: red | (green << 8) | (blue << 16) | (alpha << 24). Fully opaque uses an alpha of 255.

It makes no difference when GDI rendering is active (as per the default), but DirectWrite will read a 24-bit RGB value as having a 0 alpha byte:

An application moving to Direct2D will also obtain the following features:

  • [ . . .]
  • The ability to support Grayscale text rendering. This correctly populates the destination alpha channel according to both the text brush opacity and the antialiasing of the text.

https://docs.microsoft.com/en-us/windows/win32/direct2d/direct2d-and-directwrite#glyph-rendering

@jabal1
Copy link
Author

jabal1 commented Jun 24, 2022

@d0vgan & @rdipardo

Thanks a lot to both of you !

The commands you indicated indeed solved my problem ! 👍

I am quite astonished and pleased by your in-depth knowledge of Scintilla, Notepad++ and its plugins ! 🥇

Thanks again for the support !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants