Community
    • Login

    How to change color of letters of highlighted text?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    11 Posts 7 Posters 8.4k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Nick BrownN
      Nick Brown @Evgeny Morozov
      last edited by

      @Evgeny-Morozov

      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.
      4ca166e9-43ca-4754-9436-94fc25be059f-image.png

      Evgeny MorozovE 1 Reply Last reply Reply Quote 0
      • Evgeny MorozovE
        Evgeny Morozov @Nick Brown
        last edited by

        @Nick-Brown said in How to change color of letters of highlighted text?:

        @Evgeny-Morozov

        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.
        4ca166e9-43ca-4754-9436-94fc25be059f-image.png

        Trere is no way to change color of letters of highlighted text?
        Have I understood you right?

        1 Reply Last reply Reply Quote 0
        • EkopalypseE
          Ekopalypse
          last edited by

          @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.

          1 Reply Last reply Reply Quote 0
          • guy038G
            guy038
            last edited by guy038

            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 or Python or Lua 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

            Evgeny MorozovE 1 Reply Last reply Reply Quote 4
            • Evgeny MorozovE
              Evgeny Morozov @guy038
              last edited by

              @guy038 said in How to change color of letters of highlighted text?:

              editor.setSelFore(1,(Red,Green,Blue))

              It woooooooooooooooooooooorks!

              Thanks a lot!!!

              Alan KilbornA 1 Reply Last reply Reply Quote 1
              • Alan KilbornA
                Alan Kilborn @Evgeny Morozov
                last edited by

                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:

                d18b07d4-1bf7-4d2f-bcb2-99af151d3093-image.png

                BUT…At some point later, it changes on its own to white on grey, which isn’t nearly as desirable:

                71540199-06ba-4e3b-b878-982a566a5450-image.png

                I did a N++ Find in Files search across all of my Pythonscripts, looking for setSelFore and setSelBack 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.

                Michael VincentM 1 Reply Last reply Reply Quote 1
                • Michael VincentM
                  Michael Vincent @Alan Kilborn
                  last edited by

                  @Alan-Kilborn

                  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.

                  Alan KilbornA 1 Reply Last reply Reply Quote 4
                  • Alan KilbornA
                    Alan Kilborn @Michael Vincent
                    last edited by Alan Kilborn

                    @Michael-Vincent

                    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).

                    1 Reply Last reply Reply Quote 3
                    • Alan KilbornA
                      Alan Kilborn
                      last edited by

                      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:

                      17877bd2-2b8c-4c77-8d41-641bec7837f2-image.png

                      1 Reply Last reply Reply Quote 1
                      • fdsafds fdsafdsaF
                        fdsafds fdsafdsa
                        last edited by

                        Settings>Style Configurator>Selected Text color

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post
                        The Community of users of the Notepad++ text editor.
                        Powered by NodeBB | Contributors