activeDocument.selection returning unselected text

activeDocument.selection returning unselected text

262
MasterMaster
262

    Jun 22, 2007#1

    I am having trouble with UltraEdit.activeDocument.selection since upgrading to UE 13.10. And the problem persist in UE 13.10+1. I have reported my problem to IDM Support, but they are having problems recreating it. So I am really looking for somebody to confirm it as a general problem - or a problem only affecting me.

    Ok, here goes:

    I'm using this simple little script:

    Code: Select all

    var selTxt = UltraEdit.activeDocument.selection;
    UltraEdit.activeDocument.write("[[[[[[[["+selTxt+"]]]]]]]]");
    I then assign it to a hot key (Shift+Ctrl+T).

    Then I switch to another file containing

    Code: Select all

    UltraEdit is an excellent replacement for NOTEPAD and a lot more...
    With the keyboard (shift + right arrow) I select the word "UltraEdit" and then invoke the script with hot key Shift+Ctrl+T. Result as expected:

    Code: Select all

    [[[[[[[[UltraEdit]]]]]]]] is an excellent replacement for NOTEPAD and a lot more...
    I then ctrl+right arrow forward in the text and selects the word "replacement" with shift+right arrow. I then invoke the script, again using the hot key - result:

    Code: Select all

    [[[[[[[[UltraEdit]]]]]]]] is an excellent [[[[[[[[NOTEPAD and]]]]]]]] for NOTEPAD and a lot more...
    Hmm, not as expected "NOTEPAD and" was in the exact position of the word "replacement" BEFORE the script was invoked initially.

    This is quite annoying as I have a number of scripts assigned to hot keys and I navigate only using the keyboard.

    If I do anything to bring the document out of focus, and back into focus, I can now select "replacement" and the correct result appears:

    Code: Select all

    [[[[[[[[UltraEdit]]]]]]]] is an excellent [[[[[[[[replacement]]]]]]]] for NOTEPAD and a lot more...
    It is as a buffer or cache of some kind is not refreshed after a UltraEdit.activeDocument.write and only refresh when bringing the document back into focus.

    6,686585
    Grand MasterGrand Master
    6,686585

      Jun 22, 2007#2

      You are right, I get the same result as you with your steps.

      It looks like for the selection the column number is not correct on second run after inserting the [ ]. The number of selected characters is correct used on second run and also the position where to insert the new string overwriting existing selection. But the selection is copied from wrong position to the variable. Pressing Ctrl+F6 and Ctrl+Shift+F6 (switch to another file and back) before second script execution solves the problem.

      Are these 2 script lines a part of a larger script or is this the whole script?

      If this is the whole script, you should better use a template for that job which works in the same way and produces only 1 undo step.
      Best regards from an UC/UE/UES for Windows user from Austria

      262
      MasterMaster
      262

        Jun 22, 2007#3

        They are indeed part of a larger script. But after my scripts started to behave strangely I narrowed the problem down to the 2 lines with activeDocument.selection and activeDocument.write.

        This way I hoped it would be simple for the IDM developers to recreate the problem instead of sending them a huge script. But alas they haven't reported back that the problem is recreated yet.

        Btw -:
        and produces only 1 undo step
        I'm working on a feature request so you can control undo levels in scripts. Sometimes it would be nice if all changes made by a script was one single undo level. (Of course "Revert to saved" can be used, but you may not nescessarily want to save a document before running a script).

        (Maybe this could even speed up scripting if UE is not going to create a undo level for every character inserted, deleted and so on).

        21
        Basic UserBasic User
        21

          Jun 25, 2007#4

          I have the problem too.
          i added a line to your script.

          Code: Select all

          var selTxt = UltraEdit.activeDocument.selection;
          UltraEdit.messageBox(selTxt);
          UltraEdit.activeDocument.write("[[[[[[[["+selTxt+"]]]]]]]]");
          
          it is very funny, what is displayed in the messagebox.
          you may make a screenshot containing the messagebox and the text, and then send it to idm.

          262
          MasterMaster
          262

            Oct 19, 2007#5

            Just a short status: The problem as described above persist in version 13.20 (and 13.20+1). No news from IDM regarding this problem.

            I have made it a habit to do a ctrl+space before invoking scripts via hot keys that I know use UltraEdit.activeDocument.selection. Evidently ctrl+space updates the "document buffer" (my pet theory anyways ;-) ) so UltraEdit.activeDocument.selection will return what's expected.

            I think I will send IDM a reminder for this problem.

              Oct 20, 2007#6

              Ok, I just wanted to do a small test in UE13.20+2 to confirm the problem, but now it (almost) seems to work.

              The approach described by me above works. And that is the way I normally work.

              "Almost" because when I undo changes made with scripts and reinvoke the script (with hot key) the result is still wrong.

              I will get some more experiences with the hotfix (all though it was not mentioned in the hotfix notes) and consider how to report the remaining problem.