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?
Advertisement
Answer
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:
- Get the two text versions you are comparing as strings.
- Call
diff_main
on the strings anddiff_cleanupSemantic
on the result, as in this code example. - Loop through the results and count the result arrays whose first element is not
0
. - Set the text contents of some element on your page to that count.
Run this updateDiffCount
function whenever the text in the textarea
is edited, after a delay.