From 46727238c75dc2257a12a1161c6b1cc15ef2bd62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Ho=CC=88=C3=9Fl?= Date: Thu, 25 Oct 2018 15:42:17 +0200 Subject: [PATCH] Diff-Bugfixes regarding replaced list items --- CHANGELOG.rst | 2 +- openslides/motions/static/js/motions/diff.js | 7 ++++--- .../motions/static/js/motions/linenumbering.js | 4 +++- tests/karma/motions/diff.service.test.js | 14 ++++++++++++++ tests/karma/motions/linenumbering.service.test.js | 8 ++++++++ 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index eec45f75b..fbcffe1c5 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -16,7 +16,7 @@ Bugfixes: - Fixed amendment csv export (added missing submitters and recommendation, removed html tags for old and new text) [#3942]. - Fixed motion/amendment diff bug: does not delete a paragraph/list item - before an new one was inserted [#3943]. + before an new one was inserted [#3943, #3946]. Version 2.3 (2018-09-20) diff --git a/openslides/motions/static/js/motions/diff.js b/openslides/motions/static/js/motions/diff.js index 8600986e6..d0bb9958a 100644 --- a/openslides/motions/static/js/motions/diff.js +++ b/openslides/motions/static/js/motions/diff.js @@ -1257,13 +1257,14 @@ angular.module('OpenSlidesApp.motions.diff', ['OpenSlidesApp.motions.lineNumberi if (lineLength !== undefined) { oldTextWithBreaks = lineNumberingService.insertLineNumbersNode(oldText, lineLength, null, firstLineNumber); - newTextWithBreaks = lineNumberingService.insertLineNumbersNode(newText, lineLength, null, firstLineNumber); + newText = lineNumberingService.insertLineBreaksWithoutNumbers(newText, lineLength); } else { oldTextWithBreaks = document.createElement('div'); oldTextWithBreaks.innerHTML = oldText; - newTextWithBreaks = document.createElement('div'); - newTextWithBreaks.innerHTML = newText; } + newText = newText.replace(/^\s+/g, '').replace(/\s+$/g, ''); + newTextWithBreaks = document.createElement('div'); + newTextWithBreaks.innerHTML = newText; for (var i = 0; i < oldTextWithBreaks.childNodes.length; i++) { currChild = oldTextWithBreaks.childNodes[i]; diff --git a/openslides/motions/static/js/motions/linenumbering.js b/openslides/motions/static/js/motions/linenumbering.js index d978e2d01..abac72007 100644 --- a/openslides/motions/static/js/motions/linenumbering.js +++ b/openslides/motions/static/js/motions/linenumbering.js @@ -68,6 +68,8 @@ angular.module('OpenSlidesApp.motions.lineNumbering', []) return this._ignoreInsertedText; } else if (this._isOsLineNumberNode(node)) { return true; + } else if (node.classList && node.classList.contains('insert')) { + return true; } else { return false; } @@ -448,7 +450,7 @@ angular.module('OpenSlidesApp.motions.lineNumbering', []) throw 'This method may only be called for ELEMENT-nodes: ' + node.nodeValue; } if (this._isIgnoredByLineNumbering(node)) { - if (this._currentInlineOffset === 0 && this._currentLineNumber !== null) { + if (this._currentInlineOffset === 0 && this._currentLineNumber !== null && this._isInlineElement(node)) { var lineNumberNode = this._createLineNumber(); if (lineNumberNode) { node.insertBefore(lineNumberNode, node.firstChild); diff --git a/tests/karma/motions/diff.service.test.js b/tests/karma/motions/diff.service.test.js index 0e32d88e1..96498931b 100644 --- a/tests/karma/motions/diff.service.test.js +++ b/tests/karma/motions/diff.service.test.js @@ -717,6 +717,20 @@ describe('linenumbering', function () { ); }); + it('works with a replaced list item', function () { + var before = "", + after = "\n", + expected = '' + + ""; + + var diff = diffService.diff(before, after, 80); + + diff = diffService._normalizeHtmlForDiff(diff); + expected = diffService._normalizeHtmlForDiff(expected); + + expect(diff.toLowerCase()).toBe(expected.toLowerCase()); + }); + it('detects broken HTML and lowercases class names', function () { var before = "

 holen, da rief sie alle sieben herbei und sprach:

\n\n

 \"Liebe Kinder, ich will hinaus in den Wald, seid auf der Hut vor dem Wolf! Wenn er
 hereinkommt, frisst er euch alle mit Haut und Haar. Der Bösewicht verstellt sich oft, aber
 an der rauen Stimme und an seinen schwarzen Füßen werdet ihr ihn schon erkennen.\"

\n\n

 Die Geißlein sagten: \" Liebe Mutter, wir wollen uns schon in acht nehmen, du kannst ohne

", after = "

holen, da rief sie alle sieben herbei und sprach:

\n\n

Hello

\n\n

World

\n\n

Ya

\n\n

Die Geißlein sagten: \" Liebe Mutter, wir wollen uns schon in acht nehmen, du kannst ohne

"; diff --git a/tests/karma/motions/linenumbering.service.test.js b/tests/karma/motions/linenumbering.service.test.js index f02c8d38a..9fe59d5a0 100644 --- a/tests/karma/motions/linenumbering.service.test.js +++ b/tests/karma/motions/linenumbering.service.test.js @@ -328,6 +328,14 @@ describe('linenumbering', function () { expect(lineNumberingService.insertLineBreaksWithoutNumbers(outHtml, 80)).toBe(outHtml); }); + it('does not count within .insert nodes', function () { + var inHtml = "

1234

1234 1234

"; + var outHtml = lineNumberingService.insertLineNumbers(inHtml, 10); + expect(outHtml).toBe('

' + noMarkup(1) + '1234

' + noMarkup(2) + '1234 1234

'); + expect(lineNumberingService.stripLineNumbers(outHtml)).toBe(inHtml); + expect(lineNumberingService.insertLineBreaksWithoutNumbers(outHtml, 80)).toBe(outHtml); + }); + it('does not create a new line for a trailing INS', function () { var inHtml = "

et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, conseteturdsfsdf23

"; var outHtml = lineNumberingService.insertLineNumbers(inHtml, 80);