Skip to content

Commit

Permalink
Fixed the deletion bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyckahn committed Sep 19, 2011
1 parent 85c05db commit 289675e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions index.html
Expand Up @@ -142,10 +142,10 @@ <h2 id="qunit-userAgent"></h2>
test('Compare shorter and shorterMissingLine:', function() {
var result = dumbDiff.lines(snippets.shorter, snippets.shorterMissingLine);
console.log(result)
equal(result.lines.length, 6, 'There were 6 different lines.');
equal(result.lines.length, 5, 'There were 5 different lines.');
//equal(result.lines[0], 'DIFFERENT LINE 2', 'Diff contains the first line that is only present in the new version.');
equal(result.rangeStart, 1, 'Diff range started at line 1.');
equal(result.rangeEnd, 7, 'Diff range ended at line 7.');
equal(result.rangeEnd, 5, 'Diff range ended at line 5.');
});

console.log(snippets);
Expand Down
5 changes: 5 additions & 0 deletions src/dumbdiff.js
Expand Up @@ -65,6 +65,11 @@
differentLines = [];
diffRangeEnd = -1;
} else {
// The new version is shorter than the old version. The diff should contain everything from the first missing line to the end of the new version.
if (newer.length < older.length) {
diffRangeEnd = newer.length;
}

differentLines = newer.slice(diffRangeStart, diffRangeEnd);
}

Expand Down

0 comments on commit 289675e

Please sign in to comment.