Reputation: 265
While using CodeMirror’s merge
addon, I am interested in knowing the count of differences found in the L.H.S. and the R.H.S. textarea
s, respectively.
Is there a way of displaying the count?
Upvotes: 3
Views: 1503
Reputation: 30398
You could implement it yourself, by using the diff-match-patch library that the merge
addon depends on. Write an updateDiffCount
function that uses the following algorithm:
diff_main
on the strings and diff_cleanupSemantic
on the result, as in this code example.0
.Run this updateDiffCount
function whenever the text in the textarea
is edited, after a delay.
Upvotes: 2
Reputation: 9469
I added some code to Rory's solution to make it easier to implement:
var text1 = document.getElementById('text1').value;
var text2 = document.getElementById('text2').value;
var d = dmp.diff_main(text1, text2);
// you can optionally add some cleanup
// dmp.diff_cleanupSemantic(d); or dmp.diff_cleanupEfficiency(d);
alert('Difference count: ' + d.filter(l => l[0] === -1).length);
Upvotes: 1