jsondiffpatch icon indicating copy to clipboard operation
jsondiffpatch copied to clipboard

textDiff option set to "0" should allow single letters to be merged instead of taking the default value 60.

Open geyang opened this issue 10 years ago • 4 comments

If you set textDiff: {minLength: 0}, the text diff falls back to the default minLength of 60 characters. This prevents two single letter commits to merge properly.

Setting minLength to 1 allows two strings with at least 2 characters to properly diff merge. However for changes such as:

"" => "a" and "" => "b" the merge simply takes the later one. If any further updates on a is made, it is also replaced by b.

geyang avatar Sep 03 '15 09:09 geyang

I see, you can't set that minimum to 0 without the default getting applied, although I'm curious in which scenario would you like to get text diffs generated for 1 char strings? that would be just way more inefficient (both in CPU cost and in the delta size) than normal diff by value, without bringing any advantage.

benjamine avatar Sep 04 '15 23:09 benjamine

haha oh well, the case is below. Thanks for this great library! The CPU cost and delta size is something we worry about at a higher level. For this library we need it to be able to handle the following case:

The key is that this minLength is the minimum length both of the two strings have to match to. In a collaboration environment, proper merge rely on Fraser's fuzzy merge algorithm to work. So substituting of a text diff with string replacement breaks the fuzzy merge.

Say we start with an empty string: Within a short 200ms, Adam adds three letters "thi", and this arrived at the server. ther server replaces the "" with "thi" and Adam is happy.

then Bob also made some change and types "red". Now with Fraser's algorithm, the merged result is properly "thired". However, unless the first diff is generated properly using Fraser's algorithm, the diff wouldn't be a nice text diff and the fuzzy patch wouldn't work. Now instead, the diff is a string replacement, and it just replaces what's already there, so Adam sees his work disappear, including the stuff he typed after "this is a little".

You can test this out here: The power in Fraser's code is the weighted fuzzy patch, and it works surprisingly well. For short strings, it completely negates the need for operational transform. I'm not sure about long strings yet.

geyang avatar Sep 05 '15 12:09 geyang

Is there a way to fully disable this mode all together? Entering a very large number works, but isn't ideal. I'll open a new issue if requested. Values of zero, null, or -1 do not disable this mode.

semireg avatar Aug 27 '18 13:08 semireg

PR to out put of text diffing https://github.com/benjamine/jsondiffpatch/pull/314 @semireg

ViktorQvarfordt avatar Nov 05 '21 09:11 ViktorQvarfordt