How to change color of letters of highlighted text?
-
You cannot set the foreground colour of the selection, only the background colour, this is so that any text that has been styled by one of the language lexers is not overridden.
-
@Nick-Brown said in How to change color of letters of highlighted text?:
You cannot set the foreground colour of the selection, only the background colour, this is so that any text that has been styled by one of the language lexers is not overridden.
Trere is no way to change color of letters of highlighted text?
Have I understood you right? -
@Evgeny-Morozov said in How to change color of letters of highlighted text?:
Trere is no way to change color of letters of highlighted text?
Yes, if the question is about an existing configuration setting, no otherwise.
-
Hello, @evgeny-morozov and All,
As said before, there is NO setting to change the color of the selected text :-(
However, if you have the
NppExec
orPython
orLua
plugin installed, refer to this post :https://community.notepad-plus-plus.org/post/18727
In a nutshell :
- With the PYTHON plugin, use : - To COLOR the FOREGROUND selection : editor.setSelFore(1,(Red,Green,Blue)), with Red, Green, Blue between 0 and 255 editor.setSelFore(1,(0xRed,0xGreen,0xBlue)), with Red, Green, Blue between 00 and FF editor.setSelFore(1,(0,0,0)) ( Default : Black ) - To COLOR the BACKGROUND selection : editor.setSelBack(1,(Red,Green,Blue)), with Red, Green, Blue between 0 and 255 editor.setSelBack(1,(0xRed,0xGreen,0xBlue)), with Red, Green, Blue between 00 and FF editor.setSelBack(1,(192,192,192)) ( Default : Grey 192 ) - With the NPPEXEC plugin, use : - To COLOR the FOREGROUND selection : SCI_SENDMSG 2067 1 Dec_Value or SCI_SENDMSG SCI_SETSELFORE 1 Dec_Value, with Dec_Value between 0 and 16777215 SCI_SENDMSG 2067 0xRRGGRR or SCI_SENDMSG SCI_SETSELFORE 1 0xRRGGRR, with RR, GG, BB between 00 and FF SCI_SENDMSG 2067 1 0 or SCI_SENDMSG SCI_SETSELFORE 1 0 ( Default : Black ) - To COLOR the BACKGROUND selection : SCI_SENDMSG 2068 1 Dec_Value or SCI_SENDMSG SCI_SETSELBACK 1 Dec_Value, with Dec_Value between 0 and 16777215 SCI_SENDMSG 2068 0xRRGGRR, or SCI_SENDMSG SCI_SETSELBACK 1 0xRRGGRR, with RR, GG, BB between 00 and FF SCI_SENDMSG 2068 1 0xC0C0C0 or SCI_SENDMSG SCI_SETSELBACK 1 0xC0C0C0 ( Default : Grey 192 ) NOTE : Dec_Value = Blue x 65536 + Green x 256 + Red, with Blue, Green, Red between 0 and 255 - With the LUA plugin, use : - To COLOR the BACKGROUND selection : editor:SetSelFore(1,Dec_Value), with Dec_Value between 0 and 16777215 editor:SetSelFore(1,0xRRGGBB), with RR, GG, BB between 00 and FF editor:SetSelFore(1,0) ( Default : Black ) - To COLOR the BACKGROUND selection : editor:SetSelBack(1,Dec_Value), with Dec_Value between 0 and 16777215 editor:SetSelBack(1,0xRRGGBB), with RR, GG, BB between 00 and FF editor:SetSelBack(1,0xC0C0C0) ( Default : Grey 192 ) NOTE : Dec_Value = Blue x 65536 + Green x 256 + Red, with Blue, Green, Red between 0 and 255
Best Regards,
guy038
-
@guy038 said in How to change color of letters of highlighted text?:
editor.setSelFore(1,(Red,Green,Blue))
It woooooooooooooooooooooorks!
Thanks a lot!!!
-
I as well would like to see the foreground of selected text changed.
Background as well (but that one is easy as there is direct access).
A nice white text on dark blue background sounds good. :-)So I change my startup.py to have:
for e in (editor1, editor2): e.setSelFore(1, (255, 255, 255)) e.setSelBack(1, (0, 0, 205))
This works, and looks good IMO:
BUT…At some point later, it changes on its own to white on grey, which isn’t nearly as desirable:
I did a N++ Find in Files search across all of my Pythonscripts, looking for
setSelFore
andsetSelBack
with no hits, so it doesn’t seem like it would be something I’m unintentionally altering after the change.Any ideas?
Workarounds gleefully accepted; if you’ve got 'em, bring 'em. -
Could it be after you open a new tab? In the Notepad++ codebase
grep
-ing for SCI_SETSELFORE/BACK returns this:notepad-plus-plus\PowerEditor\src\ScitillaComponent\ScintillaEditView.cpp:
2584: void ScintillaEditView::performGlobalStyles() 2585: { 2586: StyleArray & stylers = NppParameters::getInstance().getMiscStylerArray(); 2587: 2588: int i = stylers.getStylerIndexByName(TEXT("Current line background colour")); 2589: if (i != -1) 2590: { 2591: Style & style = stylers.getStyler(i); 2592: execute(SCI_SETCARETLINEBACK, style._bgColor); 2593: } 2594: 2595: COLORREF selectColorBack = grey; 2596: 2597: i = stylers.getStylerIndexByName(TEXT("Selected text colour")); 2598: if (i != -1) 2599: { 2600: Style & style = stylers.getStyler(i); 2601: selectColorBack = style._bgColor; 2602: } 2603: execute(SCI_SETSELBACK, 1, selectColorBack); [...]
Seems like when that is called, it will set the selection background color which I’m assuming is read from
stylers.xml
(or whichever theme you’re running). Maybe just change the theme “Selected text colour” instead of using PythonScript to do it?Cheers.
-
DOH! Good call. For some reason I thought these things “went together” – if you override one, you have to also do the other one. But…obviously not true.
And, it isn’t even a workaround!
Thanks!
Marking it as “solved” (just in my mind). -
A bit less than desirable, I noticed, is that if you do what I did and set the background of selected text to a dark blue, then a selection made in the Find result window is also backgrounded with dark blue.
But since its foreground color isn’t changed, “yuck” results: -
Settings>Style Configurator>Selected Text color