General XMetaL Discussion
XMetaL Community Forum › General XMetaL Discussion › MoveLeft() move more than one character sometimes
-
lqian July 31, 2009 at 12:13 am
MoveLeft() move more than one character sometimes
July 31, 2009 at 12:13 amParticipants 1Replies 2Last Activity 13 years, 8 months agoHi,
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?
mag3737 July 31, 2009 at 8:58 pm
Reply to: MoveLeft() move more than one character sometimes
July 31, 2009 at 8:58 pmAre 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?
Derek Read July 31, 2009 at 10:38 pm
Reply to: MoveLeft() move more than one character sometimes
July 31, 2009 at 10:38 pmEssentially 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.
-
AuthorPosts
- You must be logged in to reply to this topic.