replaceAll is now from cursor position

Help with writing and running scripts

replaceAll is now from cursor position

Postby jorrasdk » Mon Oct 15, 2007 7:54 pm

Notice to script power users:

When using
UltraEdit.activeDocument.findReplace.replaceAll=true;
UltraEdit.activeDocument.findReplace.replace("aaa","zzz");

in scripts in UE versions before 13.20 it inherited the option in the replace dialog: "Replace all is from top of file". With this option checked it acted on the whole document regardless of the cursor position.

From UE version 13.20 and on replaceAll is cursor dependent and ignores the "Replace all is from top of file" option. It replaces from the cursor position to the end of the document always. So if you want the replaceAll to act on the whole document always perform a
UltraEdit.activeDocument.top();
before
UltraEdit.activeDocument.findReplace.replace("aaa","zzz");

IDM tells me this is a feature and not a bug. So after fixing my pre-UE13.20 scripts (adding top() before every replace() ) they worked correctly again.

(I haven't checked if replaceAll in macros also need a Top command).
User avatar
jorrasdk
Master
Master
 
Posts: 275
Joined: Mon Mar 19, 2007 11:00 pm
Location: Denmark

Re: replaceAll is now from cursor position

Postby Mofi » Wed Oct 17, 2007 6:29 am

I'm afraid of the behavior of an execution of macro command Replace All "..." still depends on current status of the replace setting Replace All is From Top of File which makes the execution of macros with Replace All command unpredictable.

As I have written in Mofis Macro Reference I recommend to uncheck this replace option before running macros, especially my macros which are all designed to replace all always from current cursor position to end of file.

I will contact IDM once again to fix this - in my point of view - bug in the macro environment too.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4055
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: replaceAll is now from cursor position

Postby Mofi » Tue Dec 04, 2007 8:57 am

With UE v13.20+5 the behavior of command Replace All in the macro environment is changed. Replace All is now always independent of current state of Replace All is From Top of File in the replace dialog. This makes the macro execution predictable because it is not good to depend on a setting which cannot be specified inside the macro and can be modified by the user at any time between 2 macro executions.

If your macros currently depend on Replace All is From Top of File then modify it by inserting command Top were necessary to run the replace all from top of the file.

If you don't want to change the current cursor position insert a special string at start of the macro and before exiting the macro run a single replace to remove it and set cursor back to initial position. Or set a bookmark and go to this bookmark and toggle it to unset it before macro exit. Method with bookmark is possible only when normally not working with bookmarks.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4055
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: replaceAll is now from cursor position

Postby StaticGhost » Fri May 23, 2008 9:35 am

Hi All,

If you don't want to change the current cursor position, you can also use bookmarks - which can store cursor position if you go to Advanced > Configuration > Editor > Bookmarks and make sure "Bookmark column with line" is checked. From now on, a bookmark will remember the particular cursor position within a line, as well as the line.

Now, a macro like this will replace all in a document and return the cursor to its original position.

Code: Select all
InsertMode
ColumnModeOff
HexOff
PerlReOn
ToggleBookmark
Top
Find "bad text"
Replace All "good text"
GotoBookMark 1
ToggleBookmark

I posted about this on my blog, cos this was a small bug bear for me. :)
http://robertmarkbramprogrammer.blogspo ... m-top.html

Rob
:)
User avatar
StaticGhost
Basic User
Basic User
 
Posts: 35
Joined: Sun Nov 21, 2004 12:00 am


Return to Scripts