From 2bc1229fb9242aa0f6f373ec800aef519e955b71 Mon Sep 17 00:00:00 2001 From: Jamie Peabody Date: Sat, 4 Nov 2017 10:49:48 +0000 Subject: [PATCH] issue-69: invalidates current set of changes before editor content is replaced --- lib/mergely.css | 10 +++++++--- lib/mergely.js | 12 +++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/mergely.css b/lib/mergely.css index ab257f7..d98a025 100644 --- a/lib/mergely.css +++ b/lib/mergely.css @@ -18,12 +18,12 @@ .mergely.a.lhs.start.end, .mergely.a.rhs.end { border-bottom: 1px solid #a3d1ff; } .mergely.a.rhs { background-color: #ddeeff; } -.mergely.a.lhs.start.end.first { border-bottom: 0; border-top: 1px solid #a3d1ff; } +.mergely.a.lhs.start.end.first { border-bottom-width: 0; border-top: 1px solid #a3d1ff; } .mergely.d.lhs { background-color: #ffe9e9; } .mergely.d.lhs.end, .mergely.d.rhs.start.end { border-bottom: 1px solid #f8e8e8; } -.mergely.d.rhs.start.end.first { border-bottom: 0; border-top: 1px solid #f8e8e8; } +.mergely.d.rhs.start.end.first { border-bottom-width: 0; border-top: 1px solid #f8e8e8; } .mergely.d.lhs.start { border-top: 1px solid #f8e8e8; } .mergely.c.lhs, @@ -39,7 +39,11 @@ .mergely.current.start { border-top: 1px solid #000 !important; } .mergely.current.end { border-bottom: 1px solid #000 !important; } .mergely.current.lhs.a.start.end, -.mergely.current.rhs.d.start.end { border-top: 0 !important; } +.mergely.current.rhs.d.start.end { border-top-width: 0 !important; } + +.mergely.current.lhs.a.start.end.empty, +.mergely.current.rhs.d.start.end.empty { border-top-width: 1px !important; border-bottom-width: 0px !important; } + .mergely.current.CodeMirror-linenumber { color: #F9F9F9; font-weight: bold; background-color: #777; } .CodeMirror-linenumber { cursor: pointer; } .CodeMirror-code { color: #717171; } diff --git a/lib/mergely.js b/lib/mergely.js index 3d0bf23..2e474c5 100644 --- a/lib/mergely.js +++ b/lib/mergely.js @@ -484,9 +484,11 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, { this.unbind(); }, lhs: function(text) { + this.changes = []; // invalidate existing changes this.editor[this.id + '-lhs'].setValue(text); }, rhs: function(text) { + this.changes = []; // invalidate existing changes this.editor[this.id + '-rhs'].setValue(text); }, update: function() { @@ -796,7 +798,9 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, { // set cursors led.setCursor(Math.max(change["lhs-line-from"],0), 0); // use led.getCursor().ch ? red.setCursor(Math.max(change["rhs-line-from"],0), 0); - led.scrollIntoView({line: change["lhs-line-to"]}); + if (change["lhs-line-to"] >= 0) { + led.scrollIntoView({line: change["lhs-line-to"]}); + } }, _scrolling: function(editor_name) { @@ -1173,6 +1177,9 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, { var clazz = ['mergely', 'lhs', change['op'], 'cid-' + i]; led.addLineClass(llf, 'background', 'start'); led.addLineClass(llt, 'background', 'end'); + if (change['lhs-line-from'] < 0) { + clazz.push('empty'); + } if (current_diff == i) { if (llf != llt) { @@ -1225,6 +1232,9 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, { var clazz = ['mergely', 'rhs', change['op'], 'cid-' + i]; red.addLineClass(rlf, 'background', 'start'); red.addLineClass(rlt, 'background', 'end'); + if (change['rhs-line-from'] < 0) { + clazz.push('empty'); + } if (current_diff == i) { if (rlf != rlt) {