RichEdit的ITextRange:确定用户的光标是否在单词中?

发布于 2024-09-11 00:42:14 字数 397 浏览 3 评论 0原文

我正在使用 RichEdit 控件中的 ITextRange 。我想确定用户的光标是否正在触摸单词。

问题是调用iTextRange.expand(tomWord)将包含尾部空格:

括号表示范围:

Before: 

      weas[]el   .

After:

      [weasel   ].

我最初的计划是扩展范围,并检查它是否包含光标。但用户的光标可能是“weasel”后面的两个空格,并且范围仍会扩展以包含它。那我还能做什么呢?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

童话 2024-09-18 00:42:14

我记得遇到过类似的问题:即如何在不选择任何尾随空格的情况下选择单词。我认为像这样的 C++ 代码

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

应该为您提供正确的选择,以便您可以测试插入符号是否在选择中。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文