Behavior of .selectWord() or is it the cursor position?

Behavior of .selectWord() or is it the cursor position?

36
Basic UserBasic User
36

    Apr 09, 2008#1

    Has anyone had selectWord act strangely since the last update (I am not really sure if that's when it started, can't go back and check tho).

    Anyways, I made a script for checking the text at the cursor to see if it matches any of my predefined texts (had an old macro for this before, but it's ways faster with JS).

    ie, like this (cut down version, but it's basically it, only removed unimportant function definitions):

    Code: Select all

    setUpEnv();
    
    var word = UltraEdit.activeDocument.selectWord();
    word = UltraEdit.activeDocument.selection;
    
    switch (word)
    {
        case "dvc":
            UltraEdit.activeDocument.deleteText();
            UltraEdit.activeDocument.insertTemplate(24);
            break;
        case "dvi":
            UltraEdit.activeDocument.deleteText();
            UltraEdit.activeDocument.insertTemplate(28);
            break;
        case "dvl":
            UltraEdit.activeDocument.deleteText();
            UltraEdit.activeDocument.insertTemplate(29);
            break;
    
        .
        .
        .
        .
        
    
        default:
            var ColNum = UltraEdit.activeDocument.currentColumnNum;
            if (typeof(UltraEdit.activeDocumentIdx) == "undefined") ColNum++;
            UltraEdit.activeDocument.gotoLine(UltraEdit.activeDocument.currentLineNum, ColNum); // reset selection
    }
    
    function setUpEnv()
    {
        UltraEdit.insertMode();
        UltraEdit.columnModeOff();
        UltraEdit.activeDocument.hexOff();
        UltraEdit.ueReOn();
    }
    
    It just checks the text at the cursor and inputs the correct 'snippet' (template in this case) instead of the text. I invoke the script by pressing shift + space.

    Now, here's the thing(s):
    sometimes it seems the cursor position gets completely off, especially in conjunction with undo, results in selectWord to show contents I have no idea where it found (often chars with a value < 10 (00-0F) )

    [$replace$] doesn't seem to work as it used to when inserting from JS (the indentation is completely ignored, which I think wasn't the case previously).

    The first I solved with doing this before invoking selectWord();
    UltraEdit.activeDocument.gotoLine(0,UltraEdit.activeDocument.currentColumnNum);

    The second problem I have no idea as to how to get around, anyone has any idea? (I have a version without templates where I fix the indentation right in the script, but it'd be tedious to do for all templates)

    6,682583
    Grand MasterGrand Master
    6,682583

      Apr 10, 2008#2

      First correct

      var word = UltraEdit.activeDocument.selectWord();
      word = UltraEdit.activeDocument.selection;


      to

      UltraEdit.activeDocument.selectWord();
      var word = UltraEdit.activeDocument.selection;


      Second if you use UltraEdit.activeDocument.deleteText(); to delete the current selection [$replace$] in the template will never work because nothing is selected.

      I have not run a test script to verify if these changes solve your problem.
      Best regards from an UC/UE/UES for Windows user from Austria

      36
      Basic UserBasic User
      36

        Apr 10, 2008#3

        Mofi wrote:First correct

        var word = UltraEdit.activeDocument.selectWord();
        word = UltraEdit.activeDocument.selection;


        to

        UltraEdit.activeDocument.selectWord();
        var word = UltraEdit.activeDocument.selection;
        Sorry, that's what I have written, seems I messed up while cleaning out the code before pasting to the forum. (That change shouldn't make a difference tho, haven't tried the code in red tho).
        Mofi wrote:Second if you use UltraEdit.activeDocument.deleteText(); to delete the current selection [$replace$] in the template will never work because nothing is selected.

        I have not run a test script to verify if these changes solve your problem.
        After reading your second comment, I fixed the problem. The wanted effect of [$replace$] was reached by doing the following:

        Code: Select all

            case "mes":
                UltraEdit.activeDocument.deleteToEndOfLine();
                UltraEdit.activeDocument.selectWord();
                UltraEdit.activeDocument.insertTemplate(33);
                break;
        
        Thanks for the input Mofi!

        Still have to use the workaround to get .selectWord() to always do what it should :|