• Login
Community
  • Login

Find and Add To Selection In 7.7

Scheduled Pinned Locked Moved General Discussion
37 Posts 7 Posters 13.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.
  • E
    Ekopalypse @Alan Kilborn
    last edited by Ekopalypse May 22, 2019, 3:33 PM May 22, 2019, 3:33 PM

    @dinkumoil - I guess your nppexec script can be reduced to this

    sci_sendmsg SCI_SETSEARCHFLAGS SCFIND_WHOLEWORD
    sci_sendmsg 2690  // SCI_TARGETWHOLEDOCUMENT
    
    sci_sendmsg SCI_GETSELECTIONEMPTY
    if $(MSG_RESULT) == 1 then
      sci_sendmsg 2688  // SCI_MULTIPLESELECTADDNEXT
     
    sci_sendmsg 2689  // SCI_MULTIPLESELECTADDEACH
    

    What do you think?

    D 1 Reply Last reply May 22, 2019, 5:35 PM Reply Quote 4
    • D
      dinkumoil @Ekopalypse
      last edited by dinkumoil May 22, 2019, 5:40 PM May 22, 2019, 5:35 PM

      @Ekopalypse said:

      What do you think?

      Except the missing endif ;) - nice catch, it works!

      Seems like SCI_MULTIPLESELECTADDEACH needs an active selection and SCI_MULTIPLESELECTADDNEXT doesn’t.

      EDIT: Seems like even the endif is not necessary, I apologize. ;)

      E 1 Reply Last reply May 22, 2019, 5:43 PM Reply Quote 2
      • E
        Ekopalypse @dinkumoil
        last edited by May 22, 2019, 5:43 PM

        @dinkumoil

        aahhhhh - I constantly forget about using it. :-)
        Yes, it works without but as the syntax defines it, it should be used, imho.
        Who knows what a future update will do.

        1 Reply Last reply Reply Quote 2
        • G
          guy038
          last edited by guy038 May 22, 2019, 8:16 PM May 22, 2019, 8:15 PM

          Hi, @alan-kilborn and All,

          I admit that my enthusiasm is a bit excessive ! Just because I’m rather an old guy, which knew MS-DOS 5.0, WinWord 6 and Excel 5 and, even, some older goodies. So, I’m a little overwhelmed to see all these new powerful features ;-))

          By the way, I’m no longer surprised to create rectangular selections, over, let say, 50,000 lines , with N++, for years now ! Quite similar, except that all the cursors are aligned ;-))

          Cheers,

          guy038

          1 Reply Last reply Reply Quote 3
          • C
            cipher-1024
            last edited by cipher-1024 May 23, 2019, 1:29 AM May 23, 2019, 1:28 AM

            I thought this was a three post thread and then it was done! NPP Community delivers! I wound up putting @dail 's LuaScript into the startup script for the Lua plugin and it’s working great.

            Out of curiosity I tried installing NppExec on the 7.7 minimalist install and trying out @dinkumoil 's script but it would only select the current word and never go into multiedit mode. (7.7 32bit, NppExec 0.6RC3). There are no errors in the console. I don’t know if the minimalist version and my older, installed version are conflicting in some way, but I couldn’t get the script to work.

            @Alan-Kilborn , thanks for the python script, unfortunately I’m still on 1.0.8 so I haven’t tried it out yet. But once I’m back to being current, I will.

            My job is being inconvenient and making me do stuff, so I need to sit tight on upgrading for a bit until I have time to iron out any old plugin issues that I may run into after the upgrading. Thank you one and all. This is a great community.

            D A 2 Replies Last reply May 23, 2019, 7:57 AM Reply Quote 5
            • D
              dinkumoil @cipher-1024
              last edited by May 23, 2019, 7:57 AM

              @cipher-1024 said:

              trying out @dinkumoil 's script but it would only select the current word and never go into multiedit mode.

              I guess you only tried the first or second version of the script. The final one and the shortened version of @Ekopalypse some postings above should work.

              1 Reply Last reply Reply Quote 0
              • A
                Alan Kilborn @cipher-1024
                last edited by May 23, 2019, 12:55 PM

                @cipher-1024 said:

                I tried installing NppExec on the 7.7 minimalist install…and trying out the script…but it would only select the current word and never go into multiedit mode

                Multi-editing is disabled in a clean install or a portable install:

                Imgur

                Did you go into the preferences and enable it like this?:

                Imgur

                Alternatively, this can be added at the top of the NppExec script, to turn multi-selection ability ON:

                sci_sendmsg 2563 1

                Here’s where the 2563 comes from, in the Scintilla interface file:

                # Set whether multiple selections can be made
                set void SetMultipleSelection=2563(bool multipleSelection,)
                
                A 1 Reply Last reply Jun 3, 2019, 10:30 PM Reply Quote 6
                • A
                  Alan Kilborn
                  last edited by May 23, 2019, 1:02 PM

                  …and I guess for the same reason the Pythonscript presented earlier could benefit from the addition near the top of:

                  editor.setMultipleSelection(True) # in case not enabled in the Preferences

                  1 Reply Last reply Reply Quote 3
                  • C
                    cipher-1024
                    last edited by May 23, 2019, 4:29 PM

                    @Alan-Kilborn , you got it in one. Who would have thought you’d have to enable multi-edit to multi-edit… NppExec script is working on my 7.7 test install. Thanks again.

                    1 Reply Last reply Reply Quote 2
                    • A
                      AndreCunha @Alan Kilborn
                      last edited by Jun 3, 2019, 10:30 PM

                      Besides enabling Multi-Editing (as explained by @Alan-Kilborn in his comment), I just had to call the functions directly, just like Scintilla documentation specifies:

                      • SCI_MULTIPLESELECTADDNEXT adds the next occurrence of the main selection within the target to the set of selections as main. If the current selection is empty then select word around caret.

                      • SCI_MULTIPLESELECTADDEACH is similar to SCI_MULTIPLESELECTADDNEXT but adds multiple occurrences instead of just one.

                      For me, it was unnecessary to call SCI_TARGETWHOLEDOCUMENT, so, for selecting all instances of the word at once, you could just call SCI_MULTIPLESELECTADDNEXT followed by SCI_MULTIPLESELECTADDEACH:

                      // selects all instances of the selected word (or the word around the caret)
                      sci_sendmsg 2688 // SCI_MULTIPLESELECTADDNEXT
                      sci_sendmsg 2689 // SCI_MULTIPLESELECTADDEACH
                      

                      …which has the same effect of simply calling SCI_MULTIPLESELECTADDEACH twice:

                      // selects all instances of the selected word (or the word around the caret)
                      sci_sendmsg 2689 // SCI_MULTIPLESELECTADDEACH
                      sci_sendmsg 2689 // SCI_MULTIPLESELECTADDEACH
                      

                      Or, instead of blindly calling it twice, you could check if something is already selected with SCI_GETSELECTIONEMPTY (as used on other comments) and then call it only once:

                      // selects all instances of the selected word (or the word around the caret)
                      sci_sendmsg SCI_GETSELECTIONEMPTY
                      if $(MSG_RESULT) == 1 then
                        sci_sendmsg 2688 // SCI_MULTIPLESELECTADDNEXT
                      endif
                      
                      sci_sendmsg 2689 // SCI_MULTIPLESELECTADDEACH
                      

                      PS: It would be really nice to have both commands (SCI_MULTIPLESELECTADDNEXT and SCI_MULTIPLESELECTADDEACH) available for hotkeys in “Settings” > “Shortcut Mapper” > “Scintilla commands”.

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