Skip to content

Commit 60cb863

Browse files
committed
Merge pull request #5 from splewako/master
fix get_grouped_opcodes
2 parents c95b291 + 638e16b commit 60cb863

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

difflib.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ difflib = {
335335
}
336336

337337
var nn = n + n;
338+
var group = [];
338339
var groups = [];
339340
for (var idx in codes) {
340341
if (codes.hasOwnProperty(idx)) {
@@ -345,16 +346,18 @@ difflib = {
345346
j1 = code[3];
346347
j2 = code[4];
347348
if (tag == 'equal' && i2 - i1 > nn) {
348-
groups.push([tag, i1, Math.min(i2, i1 + n), j1, Math.min(j2, j1 + n)]);
349+
group.push([tag, i1, Math.min(i2, i1 + n), j1, Math.min(j2, j1 + n)]);
350+
groups.push(group);
351+
group = [];
349352
i1 = Math.max(i1, i2-n);
350353
j1 = Math.max(j1, j2-n);
351354
}
352355

353-
groups.push([tag, i1, i2, j1, j2]);
356+
group.push([tag, i1, i2, j1, j2]);
354357
}
355358
}
356359

357-
if (groups && groups[groups.length - 1][0] == 'equal') groups.pop();
360+
if (group && !(group.length == 1 && group[0][0] == 'equal')) groups.push(group)
358361

359362
return groups;
360363
}

0 commit comments

Comments
 (0)