Line break algorithm should not be distracted by newline characters
- Cancel out newlines inserted when inline-editing motions - Bugfix for newlines after BRs
This commit is contained in:
parent
1fafd74dfa
commit
ee37cfed9c
@ -37,7 +37,7 @@ Motions:
|
|||||||
- Added config value for pagenumber alignment in PDF [#3327].
|
- Added config value for pagenumber alignment in PDF [#3327].
|
||||||
- Bugfix: Several bugfixes regarding splitting list items in
|
- Bugfix: Several bugfixes regarding splitting list items in
|
||||||
change recommendations [#3288].
|
change recommendations [#3288].
|
||||||
- Bugfix: Several bugfixes regarding diff version [#3407, #3408].
|
- Bugfix: Several bugfixes regarding diff version [#3407, #3408, #3410].
|
||||||
- Added inline Editing for motion reason [#3361].
|
- Added inline Editing for motion reason [#3361].
|
||||||
- Added multiselect filter for motion comments [#3372].
|
- Added multiselect filter for motion comments [#3372].
|
||||||
- Added support for pinning personal notes to the window [#3360].
|
- Added support for pinning personal notes to the window [#3360].
|
||||||
|
@ -671,6 +671,8 @@ angular.module('OpenSlidesApp.motions.diff', ['OpenSlidesApp.motions.lineNumberi
|
|||||||
for (var ent in entities) {
|
for (var ent in entities) {
|
||||||
html = html.replace(new RegExp(ent, 'g'), entities[ent]);
|
html = html.replace(new RegExp(ent, 'g'), entities[ent]);
|
||||||
}
|
}
|
||||||
|
html = html.replace(/[ \n\t]+/gi, ' ');
|
||||||
|
html = html.replace(/(<\/(div|p|ul|li|blockquote>)>) /gi, "$1\n");
|
||||||
|
|
||||||
return html;
|
return html;
|
||||||
};
|
};
|
||||||
@ -1049,14 +1051,16 @@ angular.module('OpenSlidesApp.motions.diff', ['OpenSlidesApp.motions.lineNumberi
|
|||||||
// The "!!(found=...)"-construction is only used to make jshint happy :)
|
// The "!!(found=...)"-construction is only used to make jshint happy :)
|
||||||
var findDel = /<del>(.*?)<\/del>/gi,
|
var findDel = /<del>(.*?)<\/del>/gi,
|
||||||
findIns = /<ins>(.*?)<\/ins>/gi,
|
findIns = /<ins>(.*?)<\/ins>/gi,
|
||||||
found;
|
found, inner;
|
||||||
while (!!(found = findDel.exec(html))) {
|
while (!!(found = findDel.exec(html))) {
|
||||||
if (found[1].match(/<[^>]*>/)) {
|
inner = found[1].replace(/<br[^>]*>/gi, '');
|
||||||
|
if (inner.match(/<[^>]*>/)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (!!(found = findIns.exec(html))) {
|
while (!!(found = findIns.exec(html))) {
|
||||||
if (found[1].match(/<[^>]*>/)) {
|
inner = found[1].replace(/<br[^>]*>/gi, '');
|
||||||
|
if (inner.match(/<[^>]*>/)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -202,7 +202,7 @@ angular.module('OpenSlidesApp.motions.lineNumbering', [])
|
|||||||
lineBreakAt = i - 1;
|
lineBreakAt = i - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (lineBreakAt !== null && node.nodeValue[i] != ' ') {
|
if (lineBreakAt !== null && (node.nodeValue[i] !== ' ' && node.nodeValue[i] !== "\n")) {
|
||||||
var currLine = node.nodeValue.substring(currLineStart, lineBreakAt + 1);
|
var currLine = node.nodeValue.substring(currLineStart, lineBreakAt + 1);
|
||||||
addLine(currLine, highlight);
|
addLine(currLine, highlight);
|
||||||
|
|
||||||
@ -211,7 +211,7 @@ angular.module('OpenSlidesApp.motions.lineNumbering', [])
|
|||||||
lastBreakableIndex = null;
|
lastBreakableIndex = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.nodeValue[i] == ' ' || node.nodeValue[i] == '-') {
|
if (node.nodeValue[i] === ' ' || node.nodeValue[i] === '-' || node.nodeValue[i] === "\n") {
|
||||||
lastBreakableIndex = i;
|
lastBreakableIndex = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -413,6 +413,12 @@ angular.module('OpenSlidesApp.motions.lineNumbering', [])
|
|||||||
this._stripLineNumbers = function (node) {
|
this._stripLineNumbers = function (node) {
|
||||||
for (var i = 0; i < node.childNodes.length; i++) {
|
for (var i = 0; i < node.childNodes.length; i++) {
|
||||||
if (this._isOsLineBreakNode(node.childNodes[i]) || this._isOsLineNumberNode(node.childNodes[i])) {
|
if (this._isOsLineBreakNode(node.childNodes[i]) || this._isOsLineNumberNode(node.childNodes[i])) {
|
||||||
|
// If a newline character follows a line break, it's been very likely inserted by the WYSIWYG-editor
|
||||||
|
if (node.childNodes.length > (i + 1) && node.childNodes[i + 1].nodeType === TEXT_NODE) {
|
||||||
|
if (node.childNodes[i + 1].nodeValue[0] === "\n") {
|
||||||
|
node.childNodes[i + 1].nodeValue = " " + node.childNodes[i + 1].nodeValue.substring(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
node.removeChild(node.childNodes[i]);
|
node.removeChild(node.childNodes[i]);
|
||||||
i--;
|
i--;
|
||||||
} else {
|
} else {
|
||||||
@ -439,6 +445,9 @@ angular.module('OpenSlidesApp.motions.lineNumbering', [])
|
|||||||
* @param {number|null} firstLine
|
* @param {number|null} firstLine
|
||||||
*/
|
*/
|
||||||
this.insertLineNumbersNode = function (html, lineLength, highlight, firstLine) {
|
this.insertLineNumbersNode = function (html, lineLength, highlight, firstLine) {
|
||||||
|
// Removing newlines after BRs, as they lead to problems like #3410
|
||||||
|
html = html.replace(/(<br[^>]*>)[\n\r]+/gi, '$1');
|
||||||
|
|
||||||
var root = document.createElement('div');
|
var root = document.createElement('div');
|
||||||
root.innerHTML = html;
|
root.innerHTML = html;
|
||||||
|
|
||||||
|
@ -399,6 +399,12 @@ describe('linenumbering', function () {
|
|||||||
normalized = diffService._normalizeHtmlForDiff(unnormalized);
|
normalized = diffService._normalizeHtmlForDiff(unnormalized);
|
||||||
expect(normalized).toBe("<P CLASS='os-split-after os-split-before'>Test</P>");
|
expect(normalized).toBe("<P CLASS='os-split-after os-split-before'>Test</P>");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('treats newlines like spaces', function () {
|
||||||
|
var unnormalized = "<P>Test line\n\t 2</P>",
|
||||||
|
normalized = diffService._normalizeHtmlForDiff(unnormalized);
|
||||||
|
expect(normalized).toBe("<P>Test line 2</P>");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('the core diff algorithm', function () {
|
describe('the core diff algorithm', function () {
|
||||||
@ -521,7 +527,7 @@ describe('linenumbering', function () {
|
|||||||
after = "<p>sem. Nulla consequat massa quis enim. TEST<br>\nTEST</p>";
|
after = "<p>sem. Nulla consequat massa quis enim. TEST<br>\nTEST</p>";
|
||||||
var diff = diffService.diff(before, after);
|
var diff = diffService.diff(before, after);
|
||||||
|
|
||||||
expect(diff).toBe('<p>sem. Nulla consequat massa quis enim.<ins> TEST<br>' + "\n" + "TEST</ins></p>");
|
expect(diff).toBe('<p>sem. Nulla consequat massa quis enim.<ins> TEST<br> TEST</ins></p>');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not repeat the last word (2)', function () {
|
it('does not repeat the last word (2)', function () {
|
||||||
|
@ -145,6 +145,12 @@ describe('linenumbering', function () {
|
|||||||
expect(lineNumberingService.stripLineNumbers(outHtml)).toBe(inHtml);
|
expect(lineNumberingService.stripLineNumbers(outHtml)).toBe(inHtml);
|
||||||
expect(lineNumberingService.insertLineBreaksWithoutNumbers(outHtml, 80)).toBe(outHtml);
|
expect(lineNumberingService.insertLineBreaksWithoutNumbers(outHtml, 80)).toBe(outHtml);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('treats ascii newline characters like spaces', function () {
|
||||||
|
var inHtml = "<p>Test 123\nTest1</p>";
|
||||||
|
var outHtml = lineNumberingService.insertLineNumbers(inHtml, 5);
|
||||||
|
expect(outHtml).toBe('<p>' + noMarkup(1) + 'Test ' + brMarkup(2) + "123\n" + brMarkup(3) + 'Test1</p>');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@ -291,6 +297,12 @@ describe('linenumbering', function () {
|
|||||||
expect(lineNumberingService.stripLineNumbers(outHtml)).toBe(inHtml);
|
expect(lineNumberingService.stripLineNumbers(outHtml)).toBe(inHtml);
|
||||||
expect(lineNumberingService.insertLineBreaksWithoutNumbers(outHtml, 80)).toBe(outHtml);
|
expect(lineNumberingService.insertLineBreaksWithoutNumbers(outHtml, 80)).toBe(outHtml);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('cancels newlines after br-elements', function () {
|
||||||
|
var inHtml = "<p>Test 123<br>\nTest 456</p>";
|
||||||
|
var outHtml = lineNumberingService.insertLineNumbers(inHtml, 80);
|
||||||
|
expect(outHtml).toBe("<p>" + noMarkup(1) + "Test 123<br>" + noMarkup(2) + "Test 456</p>");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('line breaking without adding line numbers', function() {
|
describe('line breaking without adding line numbers', function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user