Need help with "UltraEdit.activeDocument.endSelect();

Need help with "UltraEdit.activeDocument.endSelect();

15
Basic UserBasic User
15

    Apr 28, 2009#1

    Dear Form readers,

    As a newbie I again try putting my embarrassing questions out there :(

    I would like to select two characters at the time from a text string of hex values "3C3F786D" and find the corresponding ASCII char.
    For the first part of this, I just want to read out two characters at the time using this one :

    Code: Select all

    	UltraEdit.activeDocument.top();
    	while (!UltraEdit.activeDocument.isEof()) {
    		UltraEdit.activeDocument.startSelect();
    		UltraEdit.activeDocument.key("RIGHT ARROW");
    		UltraEdit.activeDocument.key("RIGHT ARROW");
    		var CurrentChar = "";
    		CurrentChar = UltraEdit.activeDocument.selection;
    		UltraEdit.activeDocument.endSelect();
    		UltraEdit.outputWindow.write(CurrentChar);
    	}
    However, using this on the string "3C3F786D" gives me the output :

    3C
    3C3F
    3C3F78
    3C3F786D

    While I wanted

    3C
    3F
    78
    6D

    Can someone put me on the right track here please ?

    Kind regards

    Jørn

      Apr 28, 2009#2

      OK. Did a "workaround" ?

      Code: Select all

      	UltraEdit.activeDocument.top();
      	while (!UltraEdit.activeDocument.isEof()) {
      		UltraEdit.activeDocument.startSelect();
      		UltraEdit.activeDocument.key("RIGHT ARROW");
      		UltraEdit.activeDocument.key("RIGHT ARROW");
      		var CurrentChar = UltraEdit.activeDocument.selection;
      		UltraEdit.activeDocument.endSelect();
      		UltraEdit.activeDocument.key("LEFT ARROW");
      		UltraEdit.activeDocument.key("RIGHT ARROW");
      		UltraEdit.outputWindow.write(CurrentChar);
      	}
      ... and now I get the output I need.

      Kind regards

      Jørn
      Kind regards

      Jørn
      __________________________________
      Using UltraEdit 16.20.0.1011 on XPSP3

      2362
      MasterMaster
      2362

        Apr 28, 2009#3

        Glad you found the work-around.

        I noticed by your script you are trying to use endSelect() to "unselect" the selected text. This is not what this is for.

        The startSelect and endSelect According to the UE Help file:
        startSelect: Start selection. This turns the selection mode on. Any cursor movement or positioning will be with selection on and the text is selected. endSelect will stop the selection mode. The selected text will remain selected until another command causes it not to be selected as with normal editing.
        This means the correct way of writing that script should be:

        Code: Select all

        UltraEdit.activeDocument.top();
           while (!UltraEdit.activeDocument.isEof()) {
              UltraEdit.activeDocument.startSelect();
              UltraEdit.activeDocument.key("RIGHT ARROW");
              UltraEdit.activeDocument.key("RIGHT ARROW");
              UltraEdit.activeDocument.endSelect();
              var CurrentChar = UltraEdit.activeDocument.selection;
              UltraEdit.activeDocument.key("LEFT ARROW");
              UltraEdit.activeDocument.key("RIGHT ARROW");
              UltraEdit.outputWindow.write(CurrentChar);
           }
        
        Since the selected text will remain selected until another normal editing command causes it to not be selected, and there is no "cancel selection" command in the script or macro languages, then the above would be the way to do it.

        I do believe I will write IDM and request "cancel selection" macro and script language commands. I grow rather tired of using LEFT ARROW / RIGHT ARROW types of workarounds myself.

          Apr 28, 2009#4

          If you need a "cancelSelect" function, I have written one.

          Code: Select all

          function cancelSelect(x) {
            if (x.isSel()){
              var lineNum = x.currentLineNum;
              var colNum = x.currentColumnNum;
              x.key("LEFT ARROW");
              x.gotoLineSelect(lineNum,colNum);
            }
          }
          
          It should be placed in your script, and called in the following ways:

          Code: Select all

          cancelSelect(UltraEdit.activeDocument);
          
          or

          Code: Select all

          cancelSelect(UltraEdit.document[1]);
          
          It's not as efficient as just plain LEFT ARROW / RIGHT ARROW, but it is consistent if you plan on needing this functionality in numerous scripts and it will always end up in the proper cursor position no matter your starting point.
          “Don’t document the problem, fix it.” – Atli Björgvin Oddsson

          6,686585
          Grand MasterGrand Master
          6,686585

            Apr 28, 2009#5

            Nice idea, but the cursor position changes 1 column to left. Here is your script a little bit modified.

            Code: Select all

            function cancelSelect(x) {
              if (x.isSel()){
                x.endSelect();
                var lineNum = x.currentLineNum;
                var colNum = x.currentColumnNum;
                if (typeof(UltraEdit.activeDocumentIdx) == "undefined") colNum++;
                x.gotoLine(lineNum,colNum);
              }
            }
            I would be very happy if such a simple general workaround for the missing command unselect would exist also for macros. In June 2005 a wrote a feature request email to IDM about a macro command to unselect the current selection without needing any cursor movements. Looks like I'm the only one which would need such a macro/script command.
            Best regards from an UC/UE/UES for Windows user from Austria

            2362
            MasterMaster
            2362

              Apr 28, 2009#6

              Thank you for fixing my oversight of forgetting to add one. I forgot (momentarily) that the column number starts at zero for UltraEdit prior v16.00 when reading it.

              As far as others needing it, I do, and apparently so does the person who started the thread.

              Also, I have sent in a request to IDM for the feature, and have already received a response which I will share with you.
              I understand, and I see where this could be useful. We will look into including this in a future release.

              Thanks,

              Ben
              Perhaps we'll eventually get this after all. :mrgreen:
              “Don’t document the problem, fix it.” – Atli Björgvin Oddsson