Answer the question
In order to leave comments, you need to log in
Is it possible (and how if possible?) to get the diff of a text field by onChange?
There is a problem: it would be desirable to receive in onChange event of any text component the difference entered by the user with the previous version.
For example:
The Memo1 field contains:
"Hello world!", then
the user makes changes and becomes:
"Hello my world!"
those. added the word "my":
"Hello my world!"
How to effectively find out what exactly has been changed? You can compare the text before and after and find the difference using well-known algorithms, but this method does not suit me in this case, because it seems to be inefficient.
I would like to somehow track the operation that the user does and, based on it, get diff.
For example: hang a handler on onKeyUp (when entering characters or erasing using delete or backspace).
However, in addition to keyboard input, there is also copying, drag-n-drop and others, which makes this method rather cumbersome.
Maybe there is a way to hang a handler on, let's say something like this:
procedure OnTextAdd(OpType: Boolean; Str: String; Pos: Integer);
//.. где OpType - добавление или удаление текста, Str - сам текст
// Pos - позиция в исходной строке, где произведено изменение
Answer the question
In order to leave comments, you need to log in
Look in the SynEdit component sorts (replacing the standard Memo). The component is very advanced and there is the logic you need: any change in the text saves the diff for the Undo operation (TSynEditUndoList).
An example of how it is used there:
// add to undo list
fUndoList.AddChange(Item.ChangeReason, Item.ChangeStartPos,
Item.ChangeEndPos, Item.ChangeStr, Item.ChangeSelMode);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question