Skip to content

Commit

Permalink
Try to merge the line if it was modified
Browse files Browse the repository at this point in the history
  • Loading branch information
IonicaBizau committed Dec 27, 2016
1 parent 8ccc553 commit 29a83af
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,33 @@ $(function() {
// Different line was *changed*
if (newLines.length === oldLines.length) {
newLines.forEach(function (c, i) {
if (i === oldPosition.row && oldLines[i] !== c) {
var cOldLine = oldLines[i].split("");
var cNewLine = c.split("");
var mergedLine = [];
if (cOldLine.length === cNewLine.length) {
mergedLine = cNewLine;
} else {
// Some lines were removed
var wasAdded = cNewLine.length > cOldLine.length;
var added = wasAdded ? cNewLine : cOldLine;
var deleted = !wasAdded ? cNewLine : cOldLine;
var offset = 0;

added = added.slice(0, oldPosition.column + 1);
for (var ii = 0; ii < added.length; ++ii) {
if (added[ii] !== deleted[ii]) {
offset = cNewLine.length - cOldLine.length;
break;
}
}

oldPosition.column += offset;
mergedLine = cNewLine;
}
mergedLines[i] = mergedLine.join("");
return;
}
mergedLines[i] = c;
});
} else {
Expand All @@ -71,7 +98,7 @@ $(function() {
var deleted = !wasAdded ? newLines : oldLines;
var offset = 0;

added = added.slice(0, oldPosition.row);
added = added.slice(0, oldPosition.row + 1);
for (var i = 0; i < added.length; ++i) {
if (added[i] !== deleted[i]) {
offset = newLines.length - oldLines.length;
Expand Down

0 comments on commit 29a83af

Please sign in to comment.