Commit d34f4713 authored by Guillaume's avatar Guillaume

Update rowSpan and call findOverflow again to make sure that content fits

parent 6a8355c0
Pipeline #714 failed with stage
in 4 minutes and 35 seconds
......@@ -240,7 +240,9 @@ class Layout {
parent.appendChild(clone);
} else if (rebuild) {
let fragment = rebuildAncestors(node);
parent = findElement(node.parentNode, fragment);
if (node.parentNode) {
parent = findElement(node.parentNode, fragment);
}
if (!parent) {
dest.appendChild(clone);
} else if (breakToken && isText(breakToken.node) && breakToken.offset > 0) {
......@@ -458,11 +460,33 @@ class Layout {
if (!range && left >= end) {
// Check if it is a float
let isFloat = false;
// Check if the node is inside a break-inside: avoid table cell
const insideTableCell = parentOf(node, "TD", rendered);
if (insideTableCell && window.getComputedStyle(insideTableCell)["break-inside"] === "avoid") {
// breaking inside a table cell produces unexpected result, as a workaround, we forcibly avoid break inside in a cell.
prev = insideTableCell;
// Check if the node is inside a break-inside: avoid table row
const insideTableRow = parentOf(node, "TR", rendered);
const tableRow = insideTableRow || (node.nodeName === "TR" ? node : undefined);
if (tableRow) {
let rowSpanUpdated = false;
// we need to update rowspan and run overflow again as it might have changed!
let previousRow = tableRow.previousElementSibling;
let previousRowDistance = 1;
while (previousRow) {
for (let j = 0; j < previousRow.children.length; j++) {
let column = previousRow.children[j];
if (column.rowSpan && column.rowSpan > previousRowDistance) {
rowSpanUpdated = true;
column.rowSpan = column.rowSpan - (column.rowSpan - previousRowDistance);
}
}
previousRow = previousRow.previousElementSibling;
previousRowDistance++;
}
if (rowSpanUpdated) {
// run again!
return this.findOverflow(rendered, bounds);
}
}
if (insideTableRow && window.getComputedStyle(insideTableRow)["break-inside"] === "avoid") {
// breaking inside a table row produces unexpected result, as a workaround, we forcibly avoid break inside in a row.
prev = insideTableRow;
}
// Check if the node is the first and only row in the thead
else if (node.parentNode.nodeName === "THEAD" && node.parentNode.childElementCount === 1) {
......@@ -477,40 +501,6 @@ class Layout {
br = node.tagName === "BR" || node.tagName === "WBR";
}
let tableRow;
if (node.nodeName === "TR") {
tableRow = node;
} else {
tableRow = parentOf(node, "TR", rendered);
}
if (tableRow) {
// Check if the node is inside a row with a rowspan
const table = parentOf(tableRow, "TABLE", rendered);
if (table) {
let columnCount = 0;
for (const cell of Array.from(table.rows[0].cells)) {
columnCount += parseInt(cell.getAttribute("COLSPAN") || "1");
}
if (tableRow.cells.length !== columnCount) {
let previousRow = tableRow.previousSibling;
let previousRowColumnCount;
while (previousRow !== null) {
previousRowColumnCount = 0;
for (const cell of Array.from(previousRow.cells)) {
previousRowColumnCount += parseInt(cell.getAttribute("COLSPAN") || "1");
}
if (previousRowColumnCount === columnCount) {
break;
}
previousRow = previousRow.previousSibling;
}
if (previousRowColumnCount === columnCount) {
prev = previousRow;
}
}
}
}
if (prev) {
range = document.createRange();
range.selectNode(prev);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment