This is a migrated thread and some comments may be shown as answers.

Text Position of Comment in a RichTextEditor

4 Answers 149 Views
RichTextEditor
This is a migrated thread and some comments may be shown as answers.
Ashish
Top achievements
Rank 1
Ashish asked on 24 Jul 2019, 04:05 AM

I am creating a simple Text Tagging Application using the Comments feature of RichTextEditor.

The functionality is very simple, User loads Text File in a RichTextEditor and Adds a Bunch of comments. There is nothing else the user can do. There is no formatting or images.

Once the user has done commenting, he can press a button to say "Complete". Now I want to know Each comment, the Text the user selected for commenting from the Original document, and the Ordinal position of the original selection in the document.

 

I was able to get all Comment objects, All CommentRangeStart and CommentRangeEnd objects along with the Span object which has the Text. 

I am able to get what the user commented on what text. However I am not able to find the Position of the text in the original document. Please help.

Reference:

1.foreach (var start in rtf.Document.GetAnnotationMarkersOfType<CommentRangeStart>())
2.{
3.    CommentRangeEnd end = (CommentRangeEnd)start.End;
4.    Comment comment = end.Comment;
5.    Span textSpan = (Span)start.NextSibling;
6.    int positionOfText = ??
7.    msgBoxString += comment.Author + ": " + textSpan.Text + "\r\n";
8.}

 

 

4 Answers, 1 is accepted

Sort by
0
Peshito
Telerik team
answered on 26 Jul 2019, 02:02 PM
Hi Ashish,

You can get the text selected for commenting by calling selection's GetSelectedText() method.
var selectedText = rtf.Document.Selection.GetSelectedText();
Hope this helps.

Regards,
Peshito
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Ashish
Top achievements
Rank 1
answered on 02 Aug 2019, 09:22 PM

I have multiple Comment Annotations on the document. I need the Start Position of each Comment in the document. 

This code didn't help.

0
Ashish
Top achievements
Rank 1
answered on 02 Aug 2019, 09:54 PM

Please see the attached Screenshot. I was able to create comments, but now I want to read all Comments and their Offset/Ordinal Position in the main document.

 

In the attached example, I have a Comment called "Date Of Birth" on "October 28, 1955". I am able to retrieve these two things, however what I do not get is the Position of "October 28, 1955" in the document I.e. 31 in this case.

 

0
Peshito
Telerik team
answered on 06 Aug 2019, 10:18 AM
Hi Ashish,

DocumentPosition's internal implementation is created with the so-called HierarchicalIndex - an array of numbers showing the position of an element in all of its parents - e.g. the position at the beginning of the first span in the second paragraph of the third section would be [2, 1, 0, 0]. This has a variable length depending on whether the position is inside tables/nested tables. 

In order to achieve a scenario similar to yours you could use the HierarchicalIndex class and its GetHierarchicalIndexByBox method. For example:
var caretIndex = HierarchicalIndex.GetHierarchicalIndexByBox
                (this.radRichTextBox.Document.CaretPosition.GetCurrentInlineBox()).GetIndexArray();
You could also specify the caret's position at first to be the position of the selection and then get the HierarchicalIndex array:
editor.Document.CaretPosition.SetPosition(selection.Ranges.First.StartPosition.Location);

Regards,
Peshito
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
RichTextEditor
Asked by
Ashish
Top achievements
Rank 1
Answers by
Peshito
Telerik team
Ashish
Top achievements
Rank 1
Share this question
or