Pages: 1
Print
Author Topic: MoveLeft() move more than one character sometimes  (Read 4145 times)
lqian
Member

Posts: 12


« on: July 30, 2009, 06:13:32 PM »

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 <text> rules 222,  211,  209 and 208 and 211.</text>. 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?
Logged
mag3737
XMetaL Evangelist
Administrator
Member

Posts: 117

I even use XMetaL to write my business letters.


« Reply #1 on: July 31, 2009, 02:58:15 PM »

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?
Logged

Tom Magliery
JustSystems Canada, Inc.
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2621



WWW
« Reply #2 on: July 31, 2009, 04:38:53 PM »

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.
Logged
Pages: 1
Print
Jump to:  

email us