Weird behavior with editor.rereplace function
-
It is possible that another plugin is changing the target behind the scene. Or possibly Notepad++ depending on what settings are enabled.
However for me when I try it with the LuaScript plugin, it gives 66/71 as the target after doing the replace.
-
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.
-
@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
136Any other idea that I can try?
-
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.
-
@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). -
@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 -
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?
-
I am using Notepad++ v6.9.1.
-
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.
-
@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 :)
-
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.