Diff-Bugfix: don't repeat unchanged words

This commit is contained in:
Tobias Hößl 2017-03-08 21:29:34 +01:00
parent a6de228f56
commit c3bd85e5ee
2 changed files with 43 additions and 8 deletions

View File

@ -760,17 +760,17 @@ angular.module('OpenSlidesApp.motions.diff', ['OpenSlidesApp.motions.lineNumberi
};
this._tokenizeHtml = function (str) {
var splitArrayEntries = function (arr, by, prepend) {
var splitArrayEntriesEmbedSeparator = function (arr, by, prepend) {
var newArr = [];
for (var i = 0; i < arr.length; i++) {
if (arr[i][0] == '<' && (by == " " || by == "\n")) {
if (arr[i][0] === '<' && (by === " " || by === "\n")) {
// Don't split HTML tags
newArr.push(arr[i]);
continue;
}
var parts = arr[i].split(by);
if (parts.length == 1) {
if (parts.length === 1) {
newArr.push(arr[i]);
} else {
var j;
@ -793,10 +793,29 @@ angular.module('OpenSlidesApp.motions.diff', ['OpenSlidesApp.motions.lineNumberi
}
return newArr;
};
var arr = splitArrayEntries([str], '<', true);
arr = splitArrayEntries(arr, '>', false);
arr = splitArrayEntries(arr, " ", false);
arr = splitArrayEntries(arr, "\n", false);
var splitArrayEntriesSplitSeparator = function (arr, by) {
var newArr = [];
for (var i = 0; i < arr.length; i++) {
if (arr[i][0] === '<') {
newArr.push(arr[i]);
continue;
}
var parts = arr[i].split(by);
for (var j = 0; j < parts.length; j++) {
if (j > 0) {
newArr.push(by);
}
newArr.push(parts[j]);
}
}
return newArr;
};
var arr = splitArrayEntriesEmbedSeparator([str], '<', true);
arr = splitArrayEntriesEmbedSeparator(arr, '>', false);
arr = splitArrayEntriesSplitSeparator(arr, " ");
arr = splitArrayEntriesSplitSeparator(arr, ".");
arr = splitArrayEntriesEmbedSeparator(arr, "\n", false);
return arr;
};

View File

@ -416,5 +416,21 @@ describe('linenumbering', function () {
var diff = diffService.diff(before, after);
expect(diff).toBe('<P class="delete">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</P><P class="insert">(hier: Missbrauch von bewusstseinsverändernde Mittel - daher Zensiert)</P>');
});
it('does not repeat the last word (1)', function () {
var before = "<P>sem. Nulla consequat massa quis enim. </P>",
after = "<p>sem. Nulla consequat massa quis enim. TEST<br>\nTEST</p>";
var diff = diffService.diff(before, after);
expect(diff).toBe('<p>sem. Nulla consequat massa quis enim.<ins> TEST<br>' + "\n" + "TEST</ins></p>");
});
it('does not repeat the last word (2)', function () {
var before = "<P>...so frißt er Euch alle mit Haut und Haar.</P>",
after = "<p>...so frißt er Euch alle mit Haut und Haar und Augen und Därme und alles.</p>";
var diff = diffService.diff(before, after);
expect(diff).toBe("<p>...so frißt er Euch alle mit Haut und Haar<ins> und Augen und Därme und alles</ins>.</p>");
});
});
});