views:

14

answers:

1

I'm using ITextRange from a RichEdit control. I want to determine if a user's cursor is touching a word.

The problem is that calling iTextRange.expand(tomWord) will include tailing spaces:

Brackets indicate the range:

Before: 

      weas[]el   .

After:

      [weasel   ].

My original plan was to expand the range, and check if it contained the cursor. But the user's cursor could be two spaces after "weasel", and the range will still expand to contain it. So what else can I do?

+1  A: 

I can recall facing a similar problem: that is, how to select a word without selecting any trailing space. I think that code like this C++

textRange->StartOf(tomWord,tomMove,NULL);
textRange->MoveEnd(tomWord,1,NULL);

should give you the right selection, so that you can then test if the caret is in the selection.

DavidK