Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Can't change foreground color of selected text

    Help wanted · · · – – – · · ·
    4
    6
    5939
    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.
    • Martin Persson
      Martin Persson last edited by Martin Persson

      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.

      http://i.imgur.com/IffSrU1.png

      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.

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

        Hello, Martin,

        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 :

        http://www.scintilla.org/ScintillaDoc.html#SCI_SETSELFORE

        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 [0-255]

          • 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 0 is 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 255 should be rewritten, with the Python script, editor.setSelFore(1,(255,0,0)). Note the triplet’s colours : (R,G,B)

        For the reset command, the NppExec command SCI_SENDMSG 2067 0 could 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, editor:SetSelFore(1,255)

        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 :

        https://notepad-plus-plus.org/community/topic/11039/foreground-options-for-selected-text

        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 :

        https://notepad-plus-plus.org/community/topic/11039/foreground-options-for-selected-text/13

        Best regards,

        guy038

        Scott Sumner 1 Reply Last reply Reply Quote 0
        • Scott Sumner
          Scott Sumner @guy038 last edited by

          @guy038

          I tried this out and found that the Pythonscript version of one of the commands, that wasn’t exactly explicitly discussed:

          editor.setSelBack(0,(0,0,0))

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

          1 Reply Last reply Reply Quote 0
          • Claudia Frank
            Claudia Frank last edited by

            Hi,

            the call to revert needs to be

            editor.setSelFore(0,(255,0,0))
            

            only switch first parameter. 1 = use this setting, 0 = do not use this setting

            Cheers
            Claudia

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

              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 editor.setSelBack(0,(0,0,0)) command.

              I’m may be wrong, but, as for me, the two commands editor.setSelFore(0,(0,0,0)) and editor.setSelFore(0,(255,0,0)) do restore the default highlighting of the current language !

              Anyway, thanks to you, both, for your deeper explanations :-))

              Cheers,

              guy038

              P.S. :

              I, also, updated, my previous post, too, speaking about a third possibility : the Lua Script !

              1 Reply Last reply Reply Quote 0
              • Martin Persson
                Martin Persson last edited by

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

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post
                Copyright © 2014 NodeBB Forums | Contributors