diff --git a/CHANGES.md b/CHANGES.md index 3e7f5e5..f8949b4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,8 @@ # Changes +## 4.0.9 +* #106: fixes merge edge-case with add + ## 4.0.8 * chore: updated webpack diff --git a/examples/app.js b/examples/app.js index 0437acc..8bfcecf 100644 --- a/examples/app.js +++ b/examples/app.js @@ -9,10 +9,10 @@ $(document).ready(function () { }, _debug: '', lhs: function(setValue) { - setValue('the quick red fox\njumped over the hairy dog'); + setValue('a\nb\nc'); }, rhs: function(setValue) { - setValue('the quick brown fox\njumped over the lazy dog'); + setValue('a\nb\nx\nc'); } }); }); diff --git a/package.json b/package.json index d005e77..c2eb6f5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mergely", - "version": "4.0.8", + "version": "4.0.9", "description": "A javascript UI for diff/merge", "directories": { "doc": "doc", diff --git a/src/mergely.js b/src/mergely.js index bf7d7b8..58967a0 100644 --- a/src/mergely.js +++ b/src/mergely.js @@ -671,7 +671,7 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, { } else { // homebrew - var style = 'opacity:0.6;height:16px;background-color:#bfbfbf;cursor:pointer;text-align:center;color:#eee;border:1px solid #848484;margin-right:5px;margin-top:-2px;'; + var style = 'opacity:0.6;height:16px;background-color:#bfbfbf;cursor:pointer;text-align:center;color:#eee;border:1px solid #848484;margin-right:-15px;margin-top:-2px;'; merge_lhs_button = '
<
'; merge_rhs_button = '
>
'; } @@ -1496,7 +1496,8 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, { odoc.replaceRange(text, CodeMirror.Pos(ofrom, 0), CodeMirror.Pos(oto, otolen)); } else if ((oside === 'lhs' && change['op'] === 'd') || (oside === 'rhs' && change['op'] === 'a')) { if (from > 0) { - text = doc.getRange(CodeMirror.Pos(from - 1, fromlen), CodeMirror.Pos(to, tolen)); + text = doc.getRange(CodeMirror.Pos(from, fromlen), CodeMirror.Pos(to, tolen)); + ofrom += 1; } else { text = doc.getRange(CodeMirror.Pos(0, 0), CodeMirror.Pos(to + 1, 0)); } diff --git a/tests/mergely.spec.js b/tests/mergely.spec.js index 557292d..1993e0d 100644 --- a/tests/mergely.spec.js +++ b/tests/mergely.spec.js @@ -336,6 +336,12 @@ describe('mergely', function () { dir: 'lhs', name: 'delete is lines 2-3 and insert into middle of rhs' }, + { + lhs: 'a\nb\nc', + rhs: 'a\nb\nx\nc', + dir: 'lhs', + name: 'delete line 3 of length 1 of rhs and will be replaced with empty line 2 of lhs' + }, // delete 36-43 merge rhs { lhs: '\na', @@ -384,6 +390,12 @@ describe('mergely', function () { rhs: 'a\nd', dir: 'rhs', name: 'delete is lines 2-3 and insert into middle of rhs' + }, + { + lhs: 'a\nb\nc', + rhs: 'a\nb\nx\nc', + dir: 'rhs', + name: 'merge rhs line 3 of length 1 and insert after line 2 of lhs' }]; opts.forEach((opt, i) => {