Community
    • Login

    Weird behavior with editor.rereplace function

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    12 Posts 2 Posters 6.1k 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.
    • Eric ChungE
      Eric Chung
      last edited by

      I’ve just now realized that in the title I typed editor.rereplace but in the example I actually used editor.replaceTargetRE, but just for people who are wondering, I do get the same weird result no matter which command was used.

      1 Reply Last reply Reply Quote 1
      • Eric ChungE
        Eric Chung
        last edited by

        @dail
        Thanks for the reply and I’ve also repeated the same commands with LuaScript plugin on my end…unfortunately I am still getting the weird result, see below for my LuaScript console log:

        Lua 5.3.2 Copyright © 1994-2015 Lua.org, PUC-Rio

        editor:TargetFromSelection()
        editor.TargetStart
        33
        editor.TargetEnd
        107
        editor:SearchInTarget(‘beautiful’)
        66
        editor.TargetStart
        66
        editor.TargetEnd
        75
        editor:ReplaceTargetRE(‘great’)
        5
        editor.TargetStart
        0
        editor.TargetEnd
        136

        Any other idea that I can try?

        1 Reply Last reply Reply Quote 0
        • dailD
          dail
          last edited by dail

          Try putting all that in a function and calling the function. That way it will execute all the code at once and not allow another plugin (or Notepad++) to possibly mess with the target.

          1 Reply Last reply Reply Quote 0
          • Eric ChungE
            Eric Chung
            last edited by

            @dail
            I’ve just tried the same commands on a separate computer which doesn’t have Python Script or LuaScript installed before. So for the test, only LuaScript plugin is installed…but the result came back wrong as well (same weird result).

            1 Reply Last reply Reply Quote 0
            • Eric ChungE
              Eric Chung
              last edited by

              @dail
              I’ve put all the command inside a function and with that function executed with Python Script plugin, I’ve gotten the same bad result.

              Python 2.7.6-notepad++ r2 (default, Apr 21 2014, 19:26:54) [MSC v.1600 32 bit (Intel)]
              Initialisation took 140ms
              Ready.
              getting selection
              start = 33
              end = 107
              look for the word beautiful
              start = 66
              end = 75
              replacing with the word great
              start = 0
              end = 136

              1 Reply Last reply Reply Quote 0
              • dailD
                dail
                last edited by

                I don’t have PythonScript installed however this is what I did within LuaScript.

                Lua 5.3.2  Copyright (C) 1994-2015 Lua.org, PUC-Rio
                
                function f()
                	editor.SearchFlags = SCFIND_REGEXP
                	editor:TargetFromSelection()
                	print(editor.TargetStart)
                	print(editor.TargetEnd)
                	print("look for the word beautiful")
                	editor:SearchInTarget("beautiful")
                	print(editor.TargetStart)
                	print(editor.TargetEnd)
                	print("replacing with the word great")
                	editor:ReplaceTargetRE("great")
                	print(editor.TargetStart)
                	print(editor.TargetEnd)
                end
                
                f()
                33
                107
                look for the word beautiful
                66
                75
                replacing with the word great
                66
                71
                
                

                What version of Notepad++ are you using?

                1 Reply Last reply Reply Quote 0
                • Eric ChungE
                  Eric Chung
                  last edited by

                  I am using Notepad++ v6.9.1.

                  1 Reply Last reply Reply Quote 0
                  • dailD
                    dail
                    last edited by dail

                    Same here. I’m honestly not sure what is going on then. As per the Scintilla documentation the target should be the start/end. My only guess is that there is some Notepad++ setting that is messing up the target range.

                    1 Reply Last reply Reply Quote 0
                    • Eric ChungE
                      Eric Chung
                      last edited by

                      @dail
                      Good news, mystery solved. Now I can re-create this weird behavior of the replace function on your side as well. Simply go to Settings. Preferences, choose MISC., and under Clickable Link Settings, check the box next to Enable option.

                      Now run your Lua script again and you should get what I am getting. Thanks for all your help :)

                      1 Reply Last reply Reply Quote 0
                      • dailD
                        dail
                        last edited by

                        I turned on that option and it still gave me the correct results. Tried it on v6.8.3, v6.9, and v6.9.1. But at least it is working correctly for you now.

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