From 90ab7f3f5e8ec76462198bd0698af90f150a9717 Mon Sep 17 00:00:00 2001 From: Jamie Peabody Date: Sun, 14 Jul 2019 12:54:01 +0100 Subject: [PATCH] patch(issue #115): fixes merging deleted line(s) from lhs would munge rhs text (#117) * patch(issue #115): fixes merging deleted line(s) from lhs would munge rhs text * updated readme --- CHANGES.md | 16 +++++++++------ package.json | 2 +- src/mergely.js | 1 + tests/mergely.spec.js | 48 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 7 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 85d6067..18c1a2e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,13 +1,17 @@ # Changes +## 4.0.12 +* patch: fixes issue #115 merging deleted line(s) from lhs would munge rhs text +* patch: fixes two typos in README.md + ## 4.0.11 -* fixes typo in example ajax.html +* patch: fixes typo in example ajax.html ## 4.0.10 -* fixes bad 4.0.9 artifacts +* patch: fixes bad 4.0.9 artifacts ## 4.0.9 -* #106: fixes merge edge-case with add +* patch: fixes issue #106 merge edge-case with add ## 4.0.8 * chore: updated webpack @@ -17,15 +21,15 @@ ## 4.0.6 -* #89: fixes missing merge buttons +* patch: fixes issue #89 missing merge buttons ## 4.0.5 -* #85: fixes XSS vulnerability with DOM id +* patch: fixes issue #85 XSS vulnerability with DOM id ## 4.0.2 -* #83: fixes poor rendering performance +* patch: fixes issue #83 poor rendering performance ## 4.0.0 diff --git a/package.json b/package.json index c59fc76..afde725 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mergely", - "version": "4.0.11", + "version": "4.0.12", "description": "A javascript UI for diff/merge", "directories": { "doc": "doc", diff --git a/src/mergely.js b/src/mergely.js index 58967a0..f78710f 100644 --- a/src/mergely.js +++ b/src/mergely.js @@ -1504,6 +1504,7 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, { odoc.replaceRange(text, CodeMirror.Pos(ofrom - 1, 0), CodeMirror.Pos(oto + 1, 0)); } else if ((oside === 'rhs' && change['op'] === 'd') || (oside === 'lhs' && change['op'] === 'a')) { if (from > 0) { + fromlen = doc.getLine(from - 1).length + 1; text = doc.getRange(CodeMirror.Pos(from - 1, fromlen), CodeMirror.Pos(to, tolen)); } 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 1993e0d..5c5f080 100644 --- a/tests/mergely.spec.js +++ b/tests/mergely.spec.js @@ -396,6 +396,54 @@ describe('mergely', function () { rhs: 'a\nb\nx\nc', dir: 'rhs', name: 'merge rhs line 3 of length 1 and insert after line 2 of lhs' + }, + { + lhs: '\ngood', + rhs: 'good', + dir: 'rhs', + name: 'lhs has deleted line at start' + }, + { + lhs: '\na\nb\nc\ngood', + rhs: 'good', + dir: 'rhs', + name: 'lhs has multiple deleted lines at start' + }, + { + lhs: 'good\n', + rhs: 'good', + dir: 'rhs', + name: 'lhs has deleted line at end (issue #115)' + }, + { + lhs: 'good\na\nb\nc', + rhs: 'good', + dir: 'rhs', + name: 'lhs has multiple deleted lines at end (issue #115)' + }, + { + lhs: 'good', + rhs: '\ngood', + dir: 'lhs', + name: 'rhs has added line at start' + }, + { + lhs: 'good', + rhs: '\na\nb\nc\ngood', + dir: 'lhs', + name: 'rhs has multiple added lines at start' + }, + { + lhs: 'good', + rhs: 'good\n', + dir: 'lhs', + name: 'rhs has added line at end' + }, + { + lhs: 'good', + rhs: 'good\na\nb\nc', + dir: 'lhs', + name: 'rhs has multiple added lines at end' }]; opts.forEach((opt, i) => {