[英]Make the CodeMirror merge view addon display a count of differences found
您可以通過使用merge
插件所依賴的diff-match-patch庫來自己實現它。 編寫一個使用以下算法的updateDiffCount
函數:
diff_main
的字符串和diff_cleanupSemantic
的結果,因為在此代碼示例。0
的結果數組。 每當編輯textarea
中的textarea
,在延遲后運行此updateDiffCount
函數。
我在 Rory 的解決方案中添加了一些代碼以使其更易於實現:
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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.