mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-26 19:56:49 +00:00
Used a more robust heuristic for merging consecutive diffs
- Check if consecutive diffs are separate by 1 word in addition to max 3 chars. This takes care of diffs introduced by template diffs separated by the template name and creates a clean single diff. Change-Id: I9181d2ed9a07bee6ca5d5ebd6ddea84f7e2cecac
This commit is contained in:
parent
2bc066b42d
commit
f8221b128b
|
@ -148,25 +148,26 @@ var refineDiff = function( diff ) {
|
||||||
var currIns = null, currDel = null;
|
var currIns = null, currDel = null;
|
||||||
var newDiffs = [];
|
var newDiffs = [];
|
||||||
for (var i = 0; i < n; i++) {
|
for (var i = 0; i < n; i++) {
|
||||||
var d = wordDiffs[i];
|
var d = wordDiffs[i];
|
||||||
|
var dVal = d.value;
|
||||||
if (d.added) {
|
if (d.added) {
|
||||||
// Attempt to accumulate
|
// Attempt to accumulate
|
||||||
if (currIns === null) {
|
if (currIns === null) {
|
||||||
currIns = d;
|
currIns = d;
|
||||||
} else {
|
} else {
|
||||||
currIns.value = currIns.value + d.value;
|
currIns.value = currIns.value + dVal;
|
||||||
}
|
}
|
||||||
} else if (d.removed) {
|
} else if (d.removed) {
|
||||||
// Attempt to accumulate
|
// Attempt to accumulate
|
||||||
if (currDel === null) {
|
if (currDel === null) {
|
||||||
currDel = d;
|
currDel = d;
|
||||||
} else {
|
} else {
|
||||||
currDel.value = currDel.value + d.value;
|
currDel.value = currDel.value + dVal;
|
||||||
}
|
}
|
||||||
} else if ((d.value.length < 4) && currIns && currDel) {
|
} else if (((dVal.length < 4) || !dVal.match(/\s/)) && currIns && currDel) {
|
||||||
// Attempt to accumulate
|
// Attempt to accumulate
|
||||||
currIns.value = currIns.value + d.value;
|
currIns.value = currIns.value + dVal;
|
||||||
currDel.value = currDel.value + d.value;
|
currDel.value = currDel.value + dVal;
|
||||||
} else {
|
} else {
|
||||||
// Accumulation ends. Purge!
|
// Accumulation ends. Purge!
|
||||||
if (currIns !== null) {
|
if (currIns !== null) {
|
||||||
|
|
Loading…
Reference in a new issue