From 99c98d6c56de6fb1a02975fcd2ea96b847673fb2 Mon Sep 17 00:00:00 2001 From: Gabriel Wicke Date: Mon, 4 Jun 2012 10:16:05 +0200 Subject: [PATCH] Diff refinement fixes Change-Id: I11c69de0fdcd636ccd11cd0b6cb16c5acdb188b3 --- api/ParserService.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/api/ParserService.js b/api/ParserService.js index 807691ca9a..0e69e2f596 100644 --- a/api/ParserService.js +++ b/api/ParserService.js @@ -137,16 +137,23 @@ var refineDiff = function( diff ) { for ( var i = 0, l = diff.length; i < l; i++ ) { var d = diff[i]; if ( d.added ) { + if ( added ) { + out.push( added ); + } added = d; } else if ( d.removed ) { if ( added ) { var fineDiff = jsDiff.diffWords( d.value, added.value ); out.push.apply( out, fineDiff ); added = null; + } else { + out.push( d ); + } + } else { + if ( added ) { + out.push( added ); + added = null; } - } else if ( added ) { - out.push( added ); - added = null; out.push(d); } } @@ -187,6 +194,8 @@ app.get(/\/_roundtrip\/(.*)/, function(req, res){ // Use word-based diff for small articles patch = jsDiff.convertChangesToXML( jsDiff.diffWords( out, src ) ); } else { + //console.log(JSON.stringify( jsDiff.diffLines( out, src ) )); + //patch = jsDiff.convertChangesToXML( jsDiff.diffLines( out, src ) ); patch = jsDiff.convertChangesToXML( refineDiff( jsDiff.diffLines( out, src ) ) ); } res.end( '
' + patch);