General XMetaL Discussion

XMetaL Community Forum General XMetaL Discussion MoveLeft() move more than one character sometimes

  • lqian

    MoveLeft() move more than one character sometimes

    Participants 1
    Replies 2
    Last Activity 13 years, 8 months ago

    Hi,

    I have problem when I use moveLeft()  to move the cursor one character to left.

    I need to find number in text node and add markup for numbers. I process the text word by word. Using the following code, I detect if special characters are at the end of selection. If found the special character at the word end, I use moveLeft() to move the cursor to left one character.

    For example, I have rules 222,  211,  209 and 208 and 211.. For the last number 211, xMetal return '211.' as a word. Using the following code, I will get range.text contains value of '211'. The code works fine most times, but MoveLeft() move two characters at once ,in a very few cases, then I got '21' in the range text.

    range.ExtendTo(rWordEnd);
    currentWord = range.Text;

    while (containsNonAlphaNumAtEnd(currentWord))
    {
                                                           
          rTmpEnd = rWordEnd.Duplicate;
          rTmpEnd.MoveLeft(SQMovementType.sqMove);

          range.Collapse(SQCollapseDirection.sqCollapseStart);
          range.ExtendTo(rTmpEnd);

          currentWord = range.Text;
    }

    Anyone can help for this problem?

    Reply

    mag3737

    Reply to: MoveLeft() move more than one character sometimes

    Are there any particular bits of XML on which this always fails?  E.g. does it happen for any particular character at the end of the number such as '.' or something?

    Reply

    Derek Read

    Reply to: MoveLeft() move more than one character sometimes

    Essentially MoveLeft() should function as if the user was pressing that key (which is not entirely correct because the user cannot move a Range, only a Selection), but I wonder if there might be white-spaces involved here too that you are not taking into account?

    I think it might be best to either simplify the example so that it is fully executable, without any external calls to missing bits as with the call to your function 'containsNonAlphaNumAtEnd()' or perhaps provide the complete script so others can check exactly what is being tried.

    Reply

  • You must be logged in to reply to this topic.

Lost Your Password?

Products
Downloads
Support