Community
    • Login

    Strange behavior of the sort function, with zero-length column mode selection

    Scheduled Pinned Locked Moved General Discussion
    18 Posts 4 Posters 3.8k Views 1 Watching
    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.
    • Alan KilbornA Offline
      Alan Kilborn
      last edited by Alan Kilborn

      I’d think changing THIS from:

      if (_pEditView->execute(SCI_SELECTIONISRECTANGLE))
      

      to:

      if ((_pEditView->execute(SCI_SELECTIONISRECTANGLE)) || (_pEditView->execute(SCI_GETSELECTIONMODE) == SC_SEL_THIN))
      

      should fix it.

      1 Reply Last reply Reply Quote 3
      • guy038G Online
        guy038
        last edited by guy038

        Hello, @alan-kilborn, @peterjones and All,

        Many thanks for your feedback ! I now understand the problem and, certainly, the last suggestion of Alan seems the correct one !

        I’ll create a new issue, very soon ! We’ll just have to live what this tiny problem !

        Of course, we could, as well, have simply used the Stream Selection, right before the sort. In this case, the result is always correct !


        Now, Peter and Alan, I’m upset by a behavior, a bit off-topic, relative to the PythonScript plugin. Let me explain :

        On my new Windows 10 laptop, I still did not transfer all my personal data from my old XP laptop. So, in the meanwhile, I use an USB key ( E: ), containing some folders whose one is 846_x64_RC3 which contains the last locale N++ version

        After installing, as you suggested, the PythonScript plugin with the Plugins > Plugin Admin... option, I selected the Plugins > PythonScript > New Script option which created an empty Test.py file in the folder E:\846_x64_RC3\plugins\Config\PythonScript\Scripts. Then, I pasted the contents of the @pterjones script, below, and re-saved it :

        # encoding=utf-8
        """
        Derived from SelectionToRectangle.py from 22890-simplest.py, in response to https://community.notepad-plus-plus.org/topic/23564,
        which had (accidentally) changed a Column Selection to a Multi-Selection instead. This converts a multi-selection to a column-selection
        """
        from Npp import notepad, editor, SELECTIONMODE, STATUSBARSECTION
        
        #console.clear()
        #console.write("PRE:  {}..{} R:{} M:{}\n".format(editor.getSelectionStart(), editor.getSelectionEnd(), editor.selectionIsRectangle(), editor.getMultipleSelection()))
        
        if not(editor.selectionIsRectangle()) and (editor.getMultipleSelection()):
            ss,se = editor.getSelectionStart(), editor.getSelectionEnd()
            #console.write("GET:  {}..{} R:{} M:{}\n".format(editor.getSelectionStart(), editor.getSelectionEnd(), editor.selectionIsRectangle(), editor.getMultipleSelection()))
            editor.setSelection(ss,se)
            #console.write("SET:  {}..{} R:{} M:{}\n".format(editor.getSelectionStart(), editor.getSelectionEnd(), editor.selectionIsRectangle(), editor.getMultipleSelection()))
            editor.setSelectionMode( SELECTIONMODE.RECTANGLE )
            #console.write("RECT: {}..{} R:{} M:{}\n".format(editor.getSelectionStart(), editor.getSelectionEnd(), editor.selectionIsRectangle(), editor.getMultipleSelection()))
        
        notepad.activateFile(notepad.getCurrentFilename()) # use the activateFile() command to refresh UI; otherwise, it doesn't _look_ like column/rectangle select)
        #console.write("POST: {}..{} R:{} M:{}\n".format(editor.getSelectionStart(), editor.getSelectionEnd(), editor.selectionIsRectangle(), editor.getMultipleSelection()))
        

        The INPUT text was in E:\xxx.txt file and, after following the @peterjones instructions, everything was OK !


        However, I do not understand why IF I select again the Plugins > PythonScript > New Script option, this time, the Save under... windows proposes to save the future .py file in the \E folder instead of the normal location E:\846_x64_RC3\plugins\Config\PythonScript\Scripts ?!

        Do you have some hints about it ? I surely miss something obvious !

        Thanks, in advance !

        Best Regards,

        guy038

        Notepad++ v8.4.6   (64-bit)
        Build time : Sep 25 2022 - 19:51:39
        Path : E:\846_x64_RC3\notepad++.exe
        Command Line : 
        Admin mode : OFF
        Local Conf mode : ON
        Cloud Config : OFF
        OS Name : Windows 10 Pro (64-bit) 
        OS Version : 21H2
        OS Build : 19044.2075
        Current ANSI codepage : 1252
        Plugins : 
            mimeTools (2.8)
            NppConverter (4.4)
            NppExport (0.4)
            ComparePlus (1)
            BetterMultiSelection (1.5)
            PythonScript (2)
        

        The command line set gives :

        ALLUSERSPROFILE=C:\ProgramData
        APPDATA=C:\Users\Guy\AppData\Roaming
        BRB=C:\Program Files\HP\Sure Click\bin
        BRS=C:\Program Files\HP\Sure Click\servers
        CommonProgramFiles=C:\Program Files\Common Files
        CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
        CommonProgramW6432=C:\Program Files\Common Files
        COMPUTERNAME=GUYTOU
        ComSpec=C:\windows\system32\cmd.exe
        DriverData=C:\Windows\System32\Drivers\DriverData
        FPS_BROWSER_APP_PROFILE_STRING=Internet Explorer
        FPS_BROWSER_USER_PROFILE_STRING=Default
        HOMEDRIVE=C:
        HOMEPATH=\Users\Guy
        LOCALAPPDATA=C:\Users\Guy\AppData\Local
        LOGONSERVER=\\GUYTOU
        NUMBER_OF_PROCESSORS=8
        OneDrive=C:\Users\Guy\OneDrive
        OnlineServices=Online Services
        OS=Windows_NT
        Path=: E:\846_x64_RC3\notepad++.exe
        PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
        platformcode=AN
        PROCESSOR_ARCHITECTURE=AMD64
        PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 140 Stepping 1, GenuineIntel
        PROCESSOR_LEVEL=6
        PROCESSOR_REVISION=8c01
        ProgramData=C:\ProgramData
        ProgramFiles=C:\Program Files
        ProgramFiles(x86)=C:\Program Files (x86)
        ProgramW6432=C:\Program Files
        PROMPT=$P$G
        PSModulePath=C:\Program Files\WindowsPowerShell\Modules;C:\windows\system32\WindowsPowerShell\v1.0\Modules
        PUBLIC=C:\Users\Public
        RegionCode=EMEA
        SESSIONNAME=Console
        SystemDrive=C:
        SystemRoot=C:\windows
        TEMP=C:\Users\Guy\AppData\Local\Temp
        TMP=C:\Users\Guy\AppData\Local\Temp
        USERDOMAIN=GUYTOU
        USERDOMAIN_ROAMINGPROFILE=GUYTOU
        USERNAME=Guy
        USERPROFILE=C:\Users\Guy
        windir=C:\windows
        ZES_ENABLE_SYSMAN=1
        
        Terry RT Alan KilbornA 2 Replies Last reply Reply Quote 1
        • guy038G guy038 referenced this topic on
        • Terry RT Offline
          Terry R @guy038
          last edited by Terry R

          @guy038 said in Strange behavior of the sort function, with zero-length column mode selection:

          However, I do not understand why IF I select again the Plugins > PythonScript > New Script option, this time, the Save under… windows proposes to save the future .py file in the \E folder instead of the normal location E:\846_x64_RC3\plugins\Config\PythonScript\Scripts ?!

          After reading that I’m wondering if a variable has been set if the first use was in relation to the E:\ drive. Now any successive use of this will use the pre-set variable of E:\ as a starting point since it’s already set.

          Possibly a test might be to complete a fresh start of NPP and do a new script and see what the Save Under proposes.

          Terry

          1 Reply Last reply Reply Quote 0
          • Alan KilbornA Offline
            Alan Kilborn @guy038
            last edited by

            @guy038

            I also have problems with the PythonScript > New Script command suggesting a folder that isn’t the one I want. It typically suggests a folder that is the scripts folder for another version of Notepad++ that I’ve recently used. I’ve no idea why this happens; I’ve posted about this before but never came to a resolution. So…I’m just doubly careful when I save a new script, such that it is going into the correct folder!

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

              Hi All,

              Could it be connected with the fact of putting a local N++ install on a removable drive ?

              BR

              guy038

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

                Hi, @terry-r, @alan-kilborn, @peterjones and All

                I’m really perplexed !!??

                • On my USB drive, I created a new folder E:\846_x64

                • Then, I moved the npp.8.4.6.portable.x64.7z archive, that I kept, from the folder E:\846_x64_RC3 to the new folder E:\846_x64

                • I opened this archive and extracted all the contents in the E:\846_x64 folder

                • I defined my preferred parameters in Settings > Preferences...

                • And I downloaded the PythonScript plugin via the Plugin Admin

                Bingo ! I’m pleased to tell you that, whatever the current tab, as soon as I select the Plugins > PythonScript > New Script option, the Save inder window always opens in E:\846_x64\plugins\Config\PythonScript\Scripts ;-))

                • Finally, I added the ComparePlus and BetterMultiSelection plugins and everything is still OK !

                So, I don’t see why it’s OK on a local N++ install, in folder E:\846_x64 and KO on a SAME local N++ install, in folder E:\846_x64_RC3 ???

                Anyway, my problem is solved !

                Best Regards,

                guy038

                …A quarter of an hour later, even if I use my old local N++ version, within the E:\846_x64_RC3 folder, everything seems OK, again ??? Really confusing !

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

                  Hi all,

                  As promised, I created a new issue concerning this problem :

                  https://github.com/notepad-plus-plus/notepad-plus-plus/issues/12299#issue-1401062911

                  BR

                  guy038

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

                    Hello @alan-kilborn and All,

                    In the post above, of this discussion :

                    https://community.notepad-plus-plus.org/post/80361

                    You said that you met the problem, sometimes in the past and that you haven’t find a solution yet to the fact that running the Plugins > PythonScript > New Script does not open the folder Local N++ install\Plugins\Config\PythonScript\Scripts, in the case of a local N++ install !

                    I’ve already found out two ways to reproduce this wrong behavior and also how to get the right folder ! Could you, Alan, @peterjones or someone else confirm my hypotheses ?


                    A wrong folder destination, when using the Plugins > PythonScript > New Script option, may occur when :

                    • You’re trying, by mistake, to open an already opened file in your current N++ session which is not saved in the ...\Plugins\Config\PythonScript\Scripts folder

                    • You’re saving a new_x file, in a specific folder, different from the ...\Plugins\Config\PythonScript\Scripts folder


                    So, an easy solution is to re-open a Python script of your current session ! Afterwards, any use of the Plugins > PythonScript > New Script option should open the right folder ...\Plugins\Config\PythonScript\Scripts ;-))

                    Remark : Note that holding the Ctrl key, while using the Plugins\Python Scripts\Scripts\"Script Name" option, does not help in this matter :-((

                    Best Regards,

                    guy038

                    Alan KilbornA 1 Reply Last reply Reply Quote 0
                    • Alan KilbornA Offline
                      Alan Kilborn @guy038
                      last edited by

                      @guy038 said in Strange behavior of the sort function, with zero-length column mode selection:

                      two ways to reproduce this wrong behavior

                      As I never do those two actions, that isn’t a way I’m getting into the circumstance.

                      My problem with it mainly occurs when I am running a different instance of N++ to test a script in a “clean” setup. I tell it to create a New Script and it wants to save the file in the correct folder but in my daily use Notepad++.

                      I have several workarounds for this, but it is annoying behavior to say the least.

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

                        The “Strange behavior of the sort function, with zero-length column mode selection” has been SOLVED by the developers and will be in the next release, presumably 8.4.8.

                        1 Reply Last reply Reply Quote 2
                        • Alan KilbornA Offline
                          Alan Kilborn @PeterJones
                          last edited by Alan Kilborn

                          @PeterJones :

                          SelectionToRectangle.py v2022.10.06

                          In Peter’s Oct 6, 2022 11:20am posting, the script code contained this line:

                          if editor.getSelectionMode()<>SELECTIONMODE.RECTANGLE:

                          Is Peter showing his BASIC roots here by using <>?

                          Proper Python would be to use != (or so one would think… keep reading…).

                          What caused me to notice this is that I exclusively use Python3 (and PythonScript v3.x) these days, and such a thing causes an error there, e.g.

                          Python 3.12.3 (tags/v3.12.3:f6650f9, Apr  9 2024, 14:05:25) [MSC v.1938 64 bit (AMD64)]
                          >Initialisation took 3078ms
                          >Ready.
                          >>> a = 3
                          >>> a <> 4
                            File "<console>", line 1
                              a <> 4
                                ^^
                          SyntaxError: invalid syntax
                          

                          This made me dig up PythonScript 2 and try it there, where, indeed, it is fine:

                          Python 2.7.18 (v2.7.18:8d21aa21f2, Apr 20 2020, 13:25:05) [MSC v.1500 64 bit (AMD64)]
                          >Initialisation took 2703ms
                          >Ready.
                          >>> a = 3
                          >>> a <> 4
                          True
                          

                          Probably the moral to the story is to just not use <> with Python, whatever version. :-)

                          Perhaps some further interesting reading: https://stackoverflow.com/questions/16749121

                          PeterJonesP 1 Reply Last reply Reply Quote 2
                          • PeterJonesP Offline
                            PeterJones @Alan Kilborn
                            last edited by

                            @Alan-Kilborn said in Strange behavior of the sort function, with zero-length column mode selection:

                            Is Peter showing his BASIC roots here by using <>?

                            100 PRINT "BASIC FOREVER"
                            200 GOTO 100
                            
                            1 Reply Last reply Reply Quote 3

                            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                            With your input, this post could be even better 💗

                            Register Login
                            • First post
                              Last post
                            The Community of users of the Notepad++ text editor.
                            Powered by NodeBB | Contributors