Merge pull request #3026 from CatoTH/bugfix-line-numbering-diff

Several bug fixes in the diff
This commit is contained in:
Emanuel Schütze 2017-03-03 15:26:44 +01:00 committed by GitHub
commit 95c19159f8
5 changed files with 42 additions and 8 deletions

View File

@ -278,11 +278,16 @@ angular.module('OpenSlidesApp.motions', [
html = lineNumberingService.insertLineNumbers(this.getVersion(versionId).text, lineLength);
var data = diffService.extractRangeByLineNumbers(html, maxLine, null);
if (data.html !== '') {
html = data.outerContextStart + data.innerContextStart +
data.html +
data.innerContextEnd + data.outerContextEnd;
html = lineNumberingService.insertLineNumbers(html, lineLength, highlight, null, maxLine);
} else {
// Prevents empty lines at the end of the motion
html = '';
}
return html;
},
_getTextWithChangeRecommendations: function (versionId, highlight, statusCompareCb) {

View File

@ -836,8 +836,9 @@ angular.module('OpenSlidesApp.motions.diff', ['OpenSlidesApp.motions.lineNumberi
for (i = 0; i < out.n.length; i++) {
if (out.n[i].text === undefined) {
//this._outputcharcode('ins', out.n[i]);
if (out.n[i] !== "") {
str += '<ins>' + out.n[i] + "</ins>";
}
} else {
var pre = "";
@ -973,6 +974,7 @@ angular.module('OpenSlidesApp.motions.diff', ['OpenSlidesApp.motions.lineNumberi
found = found.replace(/<\/(div|p|li)[^>]*>/gi, function(match) { return '</del>' + match; });
return found;
});
diffUnnormalized = diffUnnormalized.replace(/^<del><p>(.*)<\/p><\/del>$/gi, function(match, inner) { return "<p>" + inner + "</p>"; });
var node = document.createElement('div');
node.innerHTML = diffUnnormalized;

View File

@ -24,6 +24,7 @@ angular.module('OpenSlidesApp.motions.lineNumbering', [])
this._currentInlineOffset = null;
this._currentLineNumber = null;
this._prependLineNumberToFirstText = false;
this._ignoreNextRegularLineNumber = false;
var lineNumberCache = $cacheFactory('linenumbering.service');
@ -76,6 +77,10 @@ angular.module('OpenSlidesApp.motions.lineNumbering', [])
};
this._createLineNumber = function () {
if (this._ignoreNextRegularLineNumber) {
this._ignoreNextRegularLineNumber = false;
return;
}
var node = document.createElement('span');
var lineNumber = this._currentLineNumber;
this._currentLineNumber++;
@ -142,8 +147,12 @@ angular.module('OpenSlidesApp.motions.lineNumbering', [])
out.push(service._createLineNumber());
this._currentInlineOffset = 0;
} else if (this._prependLineNumberToFirstText) {
if (this._ignoreNextRegularLineNumber) {
this._ignoreNextRegularLineNumber = false;
} else {
out.push(service._createLineNumber());
}
}
this._prependLineNumberToFirstText = false;
while (i < node.nodeValue.length) {
@ -342,6 +351,10 @@ 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) {
node.insertBefore(this._createLineNumber(), node.firstChild);
this._ignoreNextRegularLineNumber = true;
}
return node;
} else if (this._isInlineElement(node)) {
return this._insertLineNumbersToInlineNode(node, length, highlight);
@ -352,7 +365,6 @@ angular.module('OpenSlidesApp.motions.lineNumbering', [])
};
this._stripLineNumbers = function (node) {
for (var i = 0; i < node.childNodes.length; i++) {
if (this._isOsLineBreakNode(node.childNodes[i]) || this._isOsLineNumberNode(node.childNodes[i])) {
node.removeChild(node.childNodes[i]);
@ -391,6 +403,7 @@ angular.module('OpenSlidesApp.motions.lineNumbering', [])
this._currentLineNumber = 1;
}
this._prependLineNumberToFirstText = true;
this._ignoreNextRegularLineNumber = false;
return this._insertLineNumbersToNode(root, lineLength, highlight);
};

View File

@ -363,5 +363,12 @@ describe('linenumbering', function () {
expect(diff).toBe("<p>liebliche Stimme, aber deine Stimme ist rauh; du bist der <del>Wolf.' </del><ins>Wolf.'</ins></p><p><ins>Der Wolf hatte danach richtig schlechte laune, trank eine Flasche Rum,</ins></p><p><ins>machte eine Weltreise und kam danach wieder um die Ziegen zu fressen. </ins>Da gi<del>e</del>ng der</p>");
});
it('handles completely deleted paragraphs', function () {
var before = "<P>Ihr könnt ohne Sorge fortgehen.'Da meckerte die Alte und machte sich getrost auf den Weg.</P>",
after = "";
var diff = diffService.diff(before, after);
expect(diff).toBe("<p><del>Ihr könnt ohne Sorge fortgehen.'Da meckerte die Alte und machte sich getrost auf den Weg.</del></p>");
});
});
});

View File

@ -250,6 +250,13 @@ describe('linenumbering', function () {
expect(outHtml).toBe('<p>' + noMarkup(1) + 'et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata ' + brMarkup(2) + 'sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur<ins>dsfsdf23</ins></p>');
expect(lineNumberingService.stripLineNumbers(outHtml)).toBe(inHtml);
});
it('inserts the line number before the INS, if INS is the first element of the paragraph', function() {
var inHtml = "<p><ins>lauthals </ins>'liebe Kinder, ich will hinaus in den Wald, seid auf der Hut vor dem Wolf!' Und noch etwas mehr Text bis zur nächsten Zeile</p>";
var outHtml = lineNumberingService.insertLineNumbers(inHtml, 80);
expect(outHtml).toBe("<p>" + noMarkup(1) + "<ins>lauthals </ins>'liebe Kinder, ich will hinaus in den Wald, seid auf der Hut vor dem Wolf!' Und " + brMarkup(2) + "noch etwas mehr Text bis zur nächsten Zeile</p>");
expect(lineNumberingService.stripLineNumbers(outHtml)).toBe(inHtml);
});
});
describe('behavior regarding ckeditor', function() {