-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce fastDiff() #5000
Comments
LOL... when I first saw "fastdiff" I thought these are just random letters :D BTW, |
Same here, I thought WTF. |
Regarding the
which means that in a Similar could be for reverse situation:
for insertion in the middle:
Splitting the old text with the new one, will require two sets of changes:
of course in this case we could go with:
but I think case when entire old text is a substring of a new text should also be handled. Such format makes some sense for insertions (and replacements in some cases), but it's rather useless for deletions. Maybe something like:
when So to everywhere refer to
What about replacements:
Edge cases:
It makes some sense, but I'm not sure about such approach. Basically, number of insertions ( But maybe it would be better to go with something similar to what Do you have any thoughts on that @Reinmar? |
I think it'd be better to go this way. We'll have two compatible algorithms which you can interchange if needed. Also, even if Finally, the format returned by
I don't think that this is a big deal. If this is the entire text node change, it means you used a spellchecker's suggestion to make such a replacement. You can see this as one word being replaced with another word. Rather this than two insertions. So, we can optimise for this scenario, but we don't have to. |
Makes perfect sense.
Yes, I was thinking the same (but forgot about it when writing above comment:D).
I don't see a problem making it an array so it will be fully compatible with The only question is if we would like to have exactly same results in some specific cases. Consider for example:
so here the old text needs two insertions like
|
We can always tune up this algorithm later, to match eventual problems that we'll have. The simpler it will be initially, the sooner we'll see if we have any problems :) So for me, the following may happen: const old = '123';
conts new = '12ab123c3';
fastDiff( old, new );
// [ {
// "index": 2,
// "type": "insert",
// "values": "ab123c"
// } ] |
Other: Introduced `fastDiff` diffing function. Closes #235.
Extracted from https://github.com/ckeditor/ckeditor5-engine/issues/403 (see https://github.com/ckeditor/ckeditor5-engine/issues/403#issuecomment-380467350).
The whole idea behind
fastDiff
is to introduce a faster diffing function (as ourdiff
has some performance issues in specific cases) which will be able to diff two strings determining at what index was the first and last change and what text was changed.The main purpose is to use it in the renderer while implementing smart text nodes updates (https://github.com/ckeditor/ckeditor5-engine/issues/403). So based on a
fastDiff
result we would like to useCharacterData.insertData
andCharacterData.deleteData
to smartly (partially) replace exisitng text node content when rendering new text.The text was updated successfully, but these errors were encountered: