diff --git a/sw/qa/extras/uiwriter/data/tdf112160.fodt b/sw/qa/extras/uiwriter/data/tdf112160.fodt new file mode 100644 index 000000000000..d02352e4d2a6 --- /dev/null +++ b/sw/qa/extras/uiwriter/data/tdf112160.fodt @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Table1.A1 + + + + + Table1.B1 + + + + + Table1.C1 + + + + + Table1.D1 + + + + + + + Table1.A2 + + + + + Table1.B2 + + + + + Table1.C2 + + + + + Table1.D2 + + + + + + + + diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index e36ca6eb6da0..dba77fca30f0 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -266,6 +266,7 @@ public: void testTableInNestedSection(); void testTableInSectionInTable(); void testSectionInTableInTable(); + void testTdf112160(); void testLinesMoveBackwardsInSectionInTable(); #endif void testLinesInSectionInTable(); @@ -419,6 +420,7 @@ public: CPPUNIT_TEST(testTableInNestedSection); CPPUNIT_TEST(testTableInSectionInTable); CPPUNIT_TEST(testSectionInTableInTable); + CPPUNIT_TEST(testTdf112160); CPPUNIT_TEST(testLinesMoveBackwardsInSectionInTable); #endif CPPUNIT_TEST(testLinesInSectionInTable); @@ -5164,6 +5166,29 @@ void SwUiWriterTest::testSectionInTableInTable() // This crashed the layout later in SwFrame::IsFootnoteAllowed(). createDoc("tdf112109.fodt"); } + +void SwUiWriterTest::testTdf112160() +{ + // Assert that the A2 cell is on page 1. + SwDoc* pDoc = createDoc("tdf112160.fodt"); + xmlDocPtr pXmlDoc = parseLayoutDump(); + sal_uInt32 nA2CellNode = getXPath(pXmlDoc, "/root/page[1]/body/tab/row[2]/cell[1]/section/txt[last()]", "txtNodeIndex").toUInt32(); + CPPUNIT_ASSERT_EQUAL(OUString("Table1.A2"), pDoc->GetNodes()[nA2CellNode]->GetTextNode()->GetText()); + + // Append a new paragraph to the end of the A2 cell. + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + while (pWrtShell->GetCursor()->GetNode().GetIndex() < nA2CellNode) + pWrtShell->Down(/*bSelect=*/false); + pWrtShell->EndPara(); + pWrtShell->SplitNode(); + + // Assert that after A2 got extended, D2 stays on page 1. + discardDumpedLayout(); + pXmlDoc = parseLayoutDump(); + sal_uInt32 nD2CellNode = getXPath(pXmlDoc, "/root/page[1]/body/tab/row[2]/cell[last()]/section/txt[last()]", "txtNodeIndex").toUInt32(); + // This was Table1.C2, Table1.D2 was moved to the next page, unexpected. + CPPUNIT_ASSERT_EQUAL(OUString("Table1.D2"), pDoc->GetNodes()[nD2CellNode]->GetTextNode()->GetText()); +} #endif void SwUiWriterTest::testParagraphOfTextRange() diff --git a/sw/source/core/layout/sectfrm.cxx b/sw/source/core/layout/sectfrm.cxx index c9b21fc380b9..39bc17c79092 100644 --- a/sw/source/core/layout/sectfrm.cxx +++ b/sw/source/core/layout/sectfrm.cxx @@ -1622,7 +1622,14 @@ SwLayoutFrame *SwFrame::GetNextSctLeaf( MakePageType eMakePage ) InsertPage(pOldLayLeaf ? pOldLayLeaf->FindPageFrame() : FindPageFrame(), false ); // and again the whole thing - pLayLeaf = pOldLayLeaf ? pOldLayLeaf : GetNextLayoutLeaf(); + if (pCellLeaf && CanContainSplitSection(this)) + // GetNextLayoutLeaf() would refer to the next cell in the same + // row, avoid that. pCellLeaf points to the correct cell in the + // follow table, and in the next round it'll be used, as we now + // have a next page. + pLayLeaf = pCellLeaf; + else + pLayLeaf = pOldLayLeaf ? pOldLayLeaf : GetNextLayoutLeaf(); continue; } break;