From 029ca0b8e38300e7c5c13a18f57bec7191c019de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Ho=CC=88=C3=9Fl?= Date: Sat, 3 Jun 2017 11:53:11 +0200 Subject: [PATCH] Fix a bug where a single moved word was not highlighted in the diff --- openslides/motions/static/js/motions/diff.js | 19 +++++++++++++++++-- tests/karma/motions/diff.service.test.js | 8 ++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/openslides/motions/static/js/motions/diff.js b/openslides/motions/static/js/motions/diff.js index 82b962aec..208b53725 100644 --- a/openslides/motions/static/js/motions/diff.js +++ b/openslides/motions/static/js/motions/diff.js @@ -863,18 +863,33 @@ angular.module('OpenSlidesApp.motions.diff', ['OpenSlidesApp.motions.lineNumberi } } + var currOldRow = 0; for (i = 0; i < out.n.length; i++) { if (out.n[i].text === undefined) { if (out.n[i] !== "") { str += '' + out.n[i] + ""; } + } else if (out.n[i].row < currOldRow) { + str += '' + out.n[i].text + ""; } else { var pre = ""; - for (var j = out.n[i].row + 1; j < out.o.length && out.o[j].text === undefined; j++) { - pre += '' + out.o[j] + ""; + if ((i + 1) < out.n.length && out.n[i + 1].row !== undefined && out.n[i + 1].row > out.n[i].row + 1) { + for (var n = out.n[i].row + 1; n < out.n[i + 1].row; n++) { + if (out.o[n].text === undefined) { + pre += '' + out.o[n] + ""; + } else { + pre += '' + out.o[n].text + ""; + } + } + } else { + for (var j = out.n[i].row + 1; j < out.o.length && out.o[j].text === undefined; j++) { + pre += '' + out.o[j] + ""; + } } str += out.n[i].text + pre; + + currOldRow = out.n[i].row; } } } diff --git a/tests/karma/motions/diff.service.test.js b/tests/karma/motions/diff.service.test.js index 8ec67b78e..0aab1ffe5 100644 --- a/tests/karma/motions/diff.service.test.js +++ b/tests/karma/motions/diff.service.test.js @@ -479,6 +479,14 @@ describe('linenumbering', function () { expect(diff).toBe('

...so frißt er Euch alle mit Haut und Haar.

...so frißt er Euch alle mit Haut und Haar.

'); }); + + it('marks a single moved word as deleted and inserted again', function () { + var before = '

tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren bla, no sea takimata sanctus est Lorem ipsum dolor sit amet.

', + after = '

tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd bla, no sea takimata sanctus est Lorem ipsum dolor gubergren sit amet.

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

tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren bla, no sea takimata sanctus est Lorem ipsum dolor gubergren sit amet.

'); + }); }); describe('ignoring line numbers', function () {