editor - WPF RichTextBox TextChanged event - how to find deleted or inserted text? -


While creating a customized editor with RichTextBox, I have to face the problem of finding deleted / inserted text with information provided with text-spline.

event.

There are some useful data in the example, but I think that not all requirements have been included in it, assume that many paragraphs are included, and at the same time, selected text (which spans itself in several paragraphs Has happened) has been removed.

With the example of TextChangedEventArgs, you have a collection of text changes, and each change only gives you the number of deleted or added symbols and its status.

I have the only solution, to keep a copy of the document, and apply the given list of changes on it. But as the examples of texchanges do not only give us the number of symbols (and symbols) that were inserted / removed, so to show unknown symbols we have to put some special symbols (for example '?'), Whereas we Original Copy Document

After implementing all the changes in the original copy of the document, we can compare it with the updated document of the richtextbox and find mapping between unknown symbols and real people. And finally, get what we want!

Has anyone tried this before? I need your suggestions on the whole strategy, and what do you think about this approach?

Regards

This depends primarily on your use of text changes . When both join and remove in the sequence, it is theoretically impossible to know the details of each convergence, since some of the castings may have been removed later. So you have to choose what you really want:

  • For some purposes, you need to know about the exact sequence changes, even if some of the highlighted symbols Should be left as "?".
  • For other purposes you should know how the new text differs from the old, but not the exact sequence in which the changes were made.

I will use techniques to achieve each of these results. I have used both techniques in the past, so I know they are effective.

To get an accurate sequence

If you are applying it is more appropriate to log in or search for a history or specific actions .

For these uses, the process you describe is probably the best, with a possible change: "Instead of finding mapping between unknown symbols and real people"

  1. Just to scan the text of "Delete" to scan each word and then run it to find the text of "Insert".

    1. Start with the opening text and process changes in order. To put each, '?' Symbols To delete each one, remove the specified number of symbols and record them as deleted text.

    2. Start with the last text and process the changes in the reverse order. For each delete , '?' Insert symbols For each insert , remove the specified number of symbols and record them as inserted text.

    When this is complete, all your "Insert" and "Delete" change entries will contain the text related to our best knowledge, and any text which Was inserted and will be immediately removed '?'

    To get a difference

    This revision is more appropriate for comparison or version comparison.

    For these uses, just use the information of the text changes to calculate a set of integer categories of changes, which may change, then a standard difference algorithm for finding actual changes Use It is very efficient in processing incremental changes, but still gives you the best update.

    This is particularly good when you paste in the replacement paragraph which is almost like the original: Using the information of the text changes, the whole paragraph shows that it is new, but the difference (or technique Use) will only mark the symbol that is actually different.

    The code is simple to calculate the change range: change the four integers (old start, old, new start, newend) Run through each change:

    1. If the change begins before the new beginning, reduce the new start to reduce the change and reduce the amount of the old start the equal amount
    2. Once the change has been done after the new session, once it is corrected

    Once it is done, from the old document to the boundary [the old start, Old] and new document range [new start, new], then standard Use Ntr algorithms to compare them.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -