Bugfix for line numbering with CKeditor

This commit is contained in:
Tobias Hößl 2016-12-13 23:06:38 +01:00 committed by Emanuel Schütze
parent 58b8066249
commit 08cb6a3d1b
2 changed files with 23 additions and 0 deletions

View File

@ -302,6 +302,15 @@ angular.module('OpenSlidesApp.motions.lineNumbering', [])
for (i = 0; i < oldChildren.length; i++) {
if (oldChildren[i].nodeType == TEXT_NODE) {
if (!oldChildren[i].nodeValue.match(/\S/)) {
// White space nodes between block elements should be ignored
var prevIsBlock = (i > 0 && !this._isInlineElement(oldChildren[i - 1]));
var nextIsBlock = (i < oldChildren.length - 1 && !this._isInlineElement(oldChildren[i + 1]));
if ((prevIsBlock && nextIsBlock) || (i === 0 && nextIsBlock) || (i === oldChildren.length - 1 && prevIsBlock)) {
node.appendChild(oldChildren[i]);
continue;
}
}
var ret = this._textNodeToLines(oldChildren[i], length, highlight);
for (var j = 0; j < ret.length; j++) {
node.appendChild(ret[j]);

View File

@ -251,4 +251,18 @@ describe('linenumbering', function () {
expect(lineNumberingService.stripLineNumbers(outHtml)).toBe(inHtml);
});
});
describe('behavior regarding ckeditor', function() {
it('does not count empty lines, case 1', function () {
var inHtml = "<p>Line 1</p>\n\n<p>Line 2</p>";
var outHtml = lineNumberingService.insertLineNumbers(inHtml, 80);
expect(outHtml).toBe('<p>' + noMarkup(1) + 'Line 1</p>' + "\n\n" + '<p>' + noMarkup(2) + 'Line 2</p>');
});
it('does not count empty lines, case 2', function () {
var inHtml = "<ul>\n\n<li>Point 1</li>\n\n</ul>";
var outHtml = lineNumberingService.insertLineNumbers(inHtml, 80);
expect(outHtml).toBe("<ul>\n\n<li>" + noMarkup(1) + "Point 1</li>\n\n</ul>");
});
});
});