diff --git a/CHANGELOG b/CHANGELOG index 8856b753f..5ce071a13 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -37,7 +37,8 @@ Motions: - Added config value for pagenumber alignment in PDF [#3327]. - Bugfix: Several bugfixes regarding splitting list items in change recommendations [#3288]. -- Bugfix: Several bugfixes regarding diff version [#3407, #3408, #3410, #3440]. +- Bugfix: Several bugfixes regarding diff version [#3407, #3408, #3410, + #3440, #3450]. - Added inline Editing for motion reason [#3361]. - Added multiselect filter for motion comments [#3372]. - Added support for pinning personal notes to the window [#3360]. diff --git a/openslides/motions/static/js/motions/diff.js b/openslides/motions/static/js/motions/diff.js index 6ba3ec6b9..6dc646ffa 100644 --- a/openslides/motions/static/js/motions/diff.js +++ b/openslides/motions/static/js/motions/diff.js @@ -1002,29 +1002,6 @@ angular.module('OpenSlidesApp.motions.diff', ['OpenSlidesApp.motions.lineNumberi return str.replace(/^\s+/g, '').replace(/\s+$/g, '').replace(/ {2,}/g, ' '); }; - /** - * Calculates the ratio of the text affected by inline diff - * From 0 (no changes at all) to 1 (everything has changed) - * - * @param html - * @returns {number} - * @private - */ - this._calcChangeRatio = function(html) { - var lengthChanged = 0; - - html = html.replace(/(.*?)<\/del>/gi, function() { lengthChanged += arguments[1].length; return ""; }); - html = html.replace(/(.*?)<\/ins>/gi, function() { lengthChanged += arguments[1].length; return ""; }); - html = html.replace(/<.*?>/, "").trim(); - - var lengthRemaining = html.length; - if (lengthRemaining === 0 && lengthChanged === 0) { - return 0; - } else { - return (lengthChanged / (lengthChanged + lengthRemaining)); - } - }; - /** * * @param {string} html @@ -1066,12 +1043,6 @@ angular.module('OpenSlidesApp.motions.diff', ['OpenSlidesApp.motions.lineNumberi } } - // If too much of the text is changed, it's better to separate the old from new new version, - // otherwise the result looks strange - if (this._calcChangeRatio(html) > 0.66) { - return true; - } - // If non of the conditions up to now is met, we consider the diff as being sane return false; }; diff --git a/tests/karma/motions/diff.service.test.js b/tests/karma/motions/diff.service.test.js index b02c5e840..3348e4984 100644 --- a/tests/karma/motions/diff.service.test.js +++ b/tests/karma/motions/diff.service.test.js @@ -423,20 +423,14 @@ describe('linenumbering', function () { expect(diff).toBe('The brown spotted fox jumleaped over the rolling log.'); }); - it('too many changes result in separate paragraphs', function () { - var before = "

Test1 Test2 Test3 Test4 Test5 Test9

", - after = "

Test1 Test6 Test7 Test8 Test9

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

Test1 Test2 Test3 Test4 Test5 Test9

Test1 Test6 Test7 Test8 Test9

'); - }); - - it('too many changes result in separate paragraphs - special case with un-wrapped text', function () { - var before = "Test1 Test2 Test3 Test4 Test5 Test9", - after = "Test1 Test6 Test7 Test8 Test9"; - var diff = diffService.diff(before, after); - - expect(diff).toBe('Test1 Test2 Test3 Test4 Test5 Test9Test1 Test6 Test7 Test8 Test9'); + it('does not mark the last line of a paragraph as change if a long new one is appended', function () { + var before = "

 Lorem ipsum dolor sit amet, consectetuer adipiscing elit.

", + after = "

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.

\n" + + "\n" + + "

Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.

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

 Lorem ipsum dolor sit amet, consectetuer adipiscing elit.

\n" + + "

Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.

"); }); it('does not result in separate paragraphs when only the first word has changed', function () { @@ -523,13 +517,6 @@ describe('linenumbering', function () { expect(diff).toBe("

Ihr könnt ohne Sorge fortgehen.'Da meckerte die Alte und machte sich getrost auf den Weg.

"); }); - it('does not perform inline diff if there are too many changes', function () { - var before = "

Dann kam er zurück, klopfte an die Hausthür und rief 'macht auf, ihr lieben Kinder, eure Mutter ist da und hat jedem von Euch etwas mitgebarcht.' Aber der Wolf hatte seine schwarze Pfote in das Fenster gelegt, das sahen die Kinder und riefen

", - after = "

(hier: Missbrauch von bewusstseinsverändernde Mittel - daher Zensiert)

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

Dann kam er zurück, klopfte an die Hausthür und rief \'macht auf, ihr lieben Kinder, eure Mutter ist da und hat jedem von Euch etwas mitgebarcht.\' Aber der Wolf hatte seine schwarze Pfote in das Fenster gelegt, das sahen die Kinder und riefen

(hier: Missbrauch von bewusstseinsverändernde Mittel - daher Zensiert)

'); - }); - it('does not repeat the last word (1)', function () { var before = "

sem. Nulla consequat massa quis enim. 

", after = "

sem. Nulla consequat massa quis enim. TEST
\nTEST

";