We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Getting TextPosition / Word under cursor

Hi,

I am converting a lot of some interface over from standard old RichTextBox to your SfRichTextBoxAdv, but I'm having an issue with a function.

I currently execute:
Point nMousePositionCoordinate = Mouse.GetPosition(contentRTB);
TextPointer cursorPosition = contentRTB.Document.GetPositionFromPoint(nMousePositionCoordinate, false);
string frontChunk = cursorPosition .GetTextInRun(LogicalDirection.Backward);
string frontChunk = cursorPosition .GetTextInRun(LogicalDirection.Forward);

I can't seem to find a way to get a HierarchalPosition to use contentRTBAdv.Document.GetTextPosition() or anything in that realm.  Any help getting a position from mouse location or just the word under the mouse would be super helpful, thank you.



3 Replies

VM Venkatesan Mani Syncfusion Team July 10, 2017 12:06 PM UTC

Hi Kyle Steven Lewis,

Thank you for using Syncfusion products.

At present, there is no API to get the text position from the mouse point in SfRichTextBoxAdv control. We will consider your requirement as feature request and logged a feature request. We will implement this feature in our upcoming Essential studio 2017 Volume 3 release which will be available by end of July 2017. We request you to visit our website periodically for feature related updates.

Now as a workaround, we can raise the mouse down and up event manually in SfRichTextBoxAdv to update the text position at the mouse point. We can move the selection start and end text position to word start and end respectively. For more information about the text position methods, please refer our API documentation link below,
https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.Controls.RichTextBoxAdv.TextPosition.html

Then we can get the text from the selection instance. Finally, we can reset the cursor again to user editing position. We have prepared a sample to demonstrate the same. please find the sample from the following link,

Sample link:
Sample.zip.

Note: We have triggered the mouse events manually within a preview mouse move event. So, there will be noticeable delay exist in getting text on mouse move.

We are suspecting that you are trying to achieve a code editor something like. If so you can try our WPF EditControl. For more information, please refer the following UG link,
https://help.syncfusion.com/wpf/syntaxeditor/overview

Disclaimer: The date for the feature implementation is tentative and not a commitment on our parts. It may be subjected to change.

Regards,
Venkatesan M. 



KS Kyle Steven Lewis July 28, 2017 02:52 AM UTC

I do like the syntax highlighting of the edit window, I just don't like how it lacks the spell checking of the SfRichTextBoxAdv, the red squiggle spell error part to be exact.  Essentially I just need to have a custom popup window appear when hovering over certain key words without having the text cursor move there.  I understand doing it on mouse move, I mean I could even set a timer to only have it happen every 2 seconds to check, I was just curious if it could be done without moving the text cursor.Thank you for submitting my suggestion.


VM Venkatesan Mani Syncfusion Team July 28, 2017 12:31 PM UTC

Hi Kyle Steven Lewis,

Thank you for your suggestions.

As we mentioned in our previous update, we have considered API to get the text position from the mouse point in SfRichTextBoxAdv control. We will let you know once it is implemented. We request you to visit our website periodically for feature related updates.

Our SfRichTextBoxAdv supports API to spellcheck a word and return list of suggestions if the word at the given text position is misspelled. Please refer our API documentation for more information.

API reference link:
https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.Controls.RichTextBoxAdv.SfRichTextBoxAdv.html#Syncfusion_Windows_Controls_RichTextBoxAdv_SfRichTextBoxAdv_GetSpellingError_Syncfusion_Windows_Controls_RichTextBoxAdv_TextPosition_

Regards,
Venkatesan M. 


Loader.
Live Chat Icon For mobile
Up arrow icon