From afff1f35f846894f614ff8a5ae984c559845182e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Ho=CC=88=C3=9Fl?= Date: Wed, 15 Feb 2017 20:23:29 +0100 Subject: [PATCH] Solving two bugs in the diff --- openslides/motions/static/js/motions/base.js | 3 +-- openslides/motions/static/js/motions/diff.js | 11 +++++++++++ tests/karma/motions/diff.service.test.js | 12 ++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/openslides/motions/static/js/motions/base.js b/openslides/motions/static/js/motions/base.js index 4502e3793..8b9d392c0 100644 --- a/openslides/motions/static/js/motions/base.js +++ b/openslides/motions/static/js/motions/base.js @@ -736,8 +736,7 @@ angular.module('OpenSlidesApp.motions', [ oldText = data.outerContextStart + data.innerContextStart + data.html + data.innerContextEnd + data.outerContextEnd; - var diff = diffService.diff(oldText, this.text, lineLength, this.line_from); - return lineNumberingService.insertLineNumbers(diff, lineLength, highlight, null, this.line_from); + return diffService.diff(oldText, this.text, lineLength, this.line_from); }, getType: function(original_full_html) { return this.type; diff --git a/openslides/motions/static/js/motions/diff.js b/openslides/motions/static/js/motions/diff.js index 5e6598be6..f711bd815 100644 --- a/openslides/motions/static/js/motions/diff.js +++ b/openslides/motions/static/js/motions/diff.js @@ -963,6 +963,17 @@ angular.module('OpenSlidesApp.motions.diff', ['OpenSlidesApp.motions.lineNumberi if (this._diffDetectBrokenDiffHtml(diffUnnormalized)) { diff = this._diffParagraphs(htmlOld, htmlNew, lineLength, firstLineNumber); } else { + diffUnnormalized = diffUnnormalized.replace(/.*?(\n.*?)*<\/ins>/gi, function (found) { + found = found.replace(/<(div|p|li)[^>]*>/gi, function(match) { return match + ''; }); + found = found.replace(/<\/(div|p|li)[^>]*>/gi, function(match) { return '' + match; }); + return found; + }); + diffUnnormalized = diffUnnormalized.replace(/.*?(\n.*?)*<\/del>/gi, function (found) { + found = found.replace(/<(div|p|li)[^>]*>/gi, function(match) { return match + ''; }); + found = found.replace(/<\/(div|p|li)[^>]*>/gi, function(match) { return '' + match; }); + return found; + }); + var node = document.createElement('div'); node.innerHTML = diffUnnormalized; diff = node.innerHTML; diff --git a/tests/karma/motions/diff.service.test.js b/tests/karma/motions/diff.service.test.js index 1d7f6c853..3f40e6585 100644 --- a/tests/karma/motions/diff.service.test.js +++ b/tests/karma/motions/diff.service.test.js @@ -351,5 +351,17 @@ describe('linenumbering', function () { expect(diff).toBe("

Test1 Test2

Test1 Test2

"); }); + + it('handles inserted paragraphs', function () { + var before = "

liebliche Stimme, aber deine Stimme ist rauh; du bist der Wolf.' Da gieng der

", + after = "

liebliche Stimme, aber deine Stimme ist rauh; du bist der Wolf.'

\ +\ +

Der Wolf hatte danach richtig schlechte laune, trank eine Flasche Rum,

\ +\ +

machte eine Weltreise und kam danach wieder um die Ziegen zu fressen. Da ging der

"; + var diff = diffService.diff(before, after); + + expect(diff).toBe("

liebliche Stimme, aber deine Stimme ist rauh; du bist der Wolf.' Wolf.'

Der Wolf hatte danach richtig schlechte laune, trank eine Flasche Rum,

machte eine Weltreise und kam danach wieder um die Ziegen zu fressen. Da gieng der

"); + }); }); });