Text Position of Comment in a RichTextEditor

5 posts, 0 answers
  1. Ashish
    Ashish avatar
    3 posts
    Member since:
    Jul 2019

    Posted 23 Jul 2019 Link to this post

    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.}

     

     

  2. Peshito
    Admin
    Peshito avatar
    589 posts

    Posted 26 Jul 2019 Link to this post

    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.
  3. Ashish
    Ashish avatar
    3 posts
    Member since:
    Jul 2019

    Posted 02 Aug 2019 in reply to Peshito Link to this post

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

    This code didn't help.

  4. Ashish
    Ashish avatar
    3 posts
    Member since:
    Jul 2019

    Posted 02 Aug 2019 Link to this post

    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.

     

  5. Peshito
    Admin
    Peshito avatar
    589 posts

    Posted 06 Aug 2019 Link to this post

    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.
Back to Top