mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 02:23:58 +00:00
Diff refinement fixes
Change-Id: I11c69de0fdcd636ccd11cd0b6cb16c5acdb188b3
This commit is contained in:
parent
d2602c47a6
commit
99c98d6c56
|
@ -137,16 +137,23 @@ var refineDiff = function( diff ) {
|
||||||
for ( var i = 0, l = diff.length; i < l; i++ ) {
|
for ( var i = 0, l = diff.length; i < l; i++ ) {
|
||||||
var d = diff[i];
|
var d = diff[i];
|
||||||
if ( d.added ) {
|
if ( d.added ) {
|
||||||
|
if ( added ) {
|
||||||
|
out.push( added );
|
||||||
|
}
|
||||||
added = d;
|
added = d;
|
||||||
} else if ( d.removed ) {
|
} else if ( d.removed ) {
|
||||||
if ( added ) {
|
if ( added ) {
|
||||||
var fineDiff = jsDiff.diffWords( d.value, added.value );
|
var fineDiff = jsDiff.diffWords( d.value, added.value );
|
||||||
out.push.apply( out, fineDiff );
|
out.push.apply( out, fineDiff );
|
||||||
added = null;
|
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);
|
out.push(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,6 +194,8 @@ app.get(/\/_roundtrip\/(.*)/, function(req, res){
|
||||||
// Use word-based diff for small articles
|
// Use word-based diff for small articles
|
||||||
patch = jsDiff.convertChangesToXML( jsDiff.diffWords( out, src ) );
|
patch = jsDiff.convertChangesToXML( jsDiff.diffWords( out, src ) );
|
||||||
} else {
|
} else {
|
||||||
|
//console.log(JSON.stringify( jsDiff.diffLines( out, src ) ));
|
||||||
|
//patch = jsDiff.convertChangesToXML( jsDiff.diffLines( out, src ) );
|
||||||
patch = jsDiff.convertChangesToXML( refineDiff( jsDiff.diffLines( out, src ) ) );
|
patch = jsDiff.convertChangesToXML( refineDiff( jsDiff.diffLines( out, src ) ) );
|
||||||
}
|
}
|
||||||
res.end( '<pre>' + patch);
|
res.end( '<pre>' + patch);
|
||||||
|
|
Loading…
Reference in a new issue