replaceAll is now from cursor position

replaceAll is now from cursor position

262
MasterMaster
262

    Oct 16, 2007#1

    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).

    6,686585
    Grand MasterGrand Master
    6,686585

      Oct 17, 2007#2

      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.

        Dec 04, 2007#3

        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.
        Best regards from an UC/UE/UES for Windows user from Austria

        44
        Basic UserBasic User
        44

          May 23, 2008#4

          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
          :)
          UltraEdit - licensed for life!

          http://robertmarkbramprogrammer.blogspot.com