Can't change foreground color of selected text
I run windows 7 and the newest verison of notepad++ but I cant change the foreground color of selected text
Here is a screnshot of some Python code to illustrade the problem.
The screenshot if of the Swedish interface, “förgrundsfärg” mean forground color and “bakgrundsfärg” mean background color.
It seems to not change the foreground of any selected text. I know a workaround is changing the foreground of comments or background of selected text but I should not have to.
I don’t think that you can, easily, change the foreground colour of the selected text, ONLY. Indeed, the modification of the foreground colour, for selected text, is impossible, with the Style Configurator feature :-((
As a work-around, I propose to you to exploit the Scintilla notification SCI_SETSELFORE
Refer to the link below :
In order to run that command, THREE solutions are available :
To use the NppExec plugin :
Open the ^NppExec console
Type the command SCI_SENDMSG 2067 1 C, where :
C is the decimal result of the mathematical operation
Blue * 65536 + Green * 256 + Red
Blue, Green, and Red are the value of each colour, in the range
Hit the Enter key to valid this command
For instance, the command
SCI_SENDMSG 2067 1 255, followed by Enter, will change, in pure red, the foreground colour of the text of ANY selection ( normal or rectangular ), of ANY language, for all the files of the active view ! On the same way, you may change the background colour of the selection(s), with the command
SCI_SENDMSG 2068 1 C
And, as soon as the command
SCI_SENDMSG 2067 0is validated, the foreground colour, of any selected text, reflects, again, the default styled colouring, of your language ( and, of course, the simple black colour, for normal text ! )
- To use the Python Script plugin :
As I’m not acquainted to Python Script, yet, I, just, can tell that you’ll have to use, in a new script, the two commands Editor.setSelFore(1, fore) and Editor.setSelBack(1, back), where, fore, and back are the decimal value, discussed above !
Thanks to Claudia Franck, the NppExec command
SCI_SENDMSG 2067 1 255should be rewritten, with the Python script,
editor.setSelFore(1,(255,0,0)). Note the triplet's colours :
For the reset command, the NppExec command
SCI_SENDMSG 2067 0could be rewritten, with the Python script,
editor.setSelFore(0,(0,0,0)). In that command, the triplet's colours are NOT taken in account. So, it’s easier to set them all to the 0 value !
- To use the Lua script plugin :
I’m not acquainted to the Lua plugin, too, but in the console dialog, the command should be, this time,
However, I was not able to find out the command to restore the default styled colouring of the current language :-((
Even if this topic, created 10 months ago, seems quite long to read, it would, certainly, be valuable to read it :
And, also, my reply, in that topic, for performing the change of colour of the foreground selected text, automatically, with the NppExec plugin, at the address :
I tried this out and found that the Pythonscript version of one of the commands, that wasn’t exactly explicitly discussed:
does NOT restore the default selection background coloring. In fact, it seems to remove the coloring entirely, so that after it is executed, it doesn’t even appear that you are making a selection; but you are (you can delete/copy/cut/etc) the invisible selection!
Perhaps this wasn’t discussed because it is known not to work. :)
the call to revert needs to be
only switch first parameter. 1 = use this setting, 0 = do not use this setting
Hi Scott and Claudia,
So, my first attempt to find out something, in Python script, by myself, was misinterpreted ? Well, it’s just my first lesson !
Nevertheless, Scott, just note that I spoke, in my previous post, of the
editor.setSelFore(0,(0,0,0))command, for the reset part and NOT of the
I’m may be wrong, but, as for me, the two commands
editor.setSelFore(0,(255,0,0))do restore the default highlighting of the current language !
Anyway, thanks to you, both, for your deeper explanations :-))
I, also, updated, my previous post, too, speaking about a third possibility : the Lua Script !
An obvious followup question is why even have this setting if it does not work?
I excpect the option “Global Styles: Selected text colour” to mean "globally set colour of selected text ".