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

When creating a custom editor with RichTextBox, I had a problem finding the deleted / pasted text with the provided information with the TextChanged event.

The TextChangedEventArgs instance contains useful data, but I think that it does not cover all needs. Suppose that a script in which several paragraphs are inserted and at the same time the selected text (which itself spans several paragraphs) has been deleted.

With an instance of TextChangedEventArgs, you have a set of text changes, and each change only gives you the number of characters removed or added and its position.

The only solution I have in mind is to keep a copy of the document and apply this list of changes to it. But since TextChange instances give us only the number of inserted / deleted characters (not characters), so we need to put a special character (for example, '?') To indicate unknown characters, while we convert our original copy of the document.

After applying all the changes to the original copy of the document, we can compare it with the updated richtextbox document and find the mappings between unknown characters and real ones. And finally, get what we want!

Has anyone tried this before? I need your suggestions for the whole strategy and what you think about this approach.

Hi

+3
1

. , , , . , :

  • , "?".
  • , , , .

. , , .

, .

, , , : , " ", , "", , "".

:

  • . '?' . .

  • . '?' . .

, "" "" , , , , "?". .

.

, , , , . , , , .

, , . , , diff (.. ) .

: (oldstart, oldend, newstart, newend). :

  • changestart newstart, newstart changestart oldstart .
  • changeend newend, newend oldend

, [oldstart, oldend] [newstart, newend] , .

+4

Source: https://habr.com/ru/post/1731077/


All Articles