[Libreoffice-commits] core.git: sw/qa sw/source

Miklos Vajna vmiklos at collabora.co.uk
Fri Jul 14 13:15:06 UTC 2017


 sw/qa/extras/uiwriter/uiwriter.cxx |   29 +++++++++++++++++++++++++++++
 sw/source/core/layout/sectfrm.cxx  |   16 ++++++++++++++--
 2 files changed, 43 insertions(+), 2 deletions(-)

New commits:
commit 850bf99e7d1abcf2e0cce731b6715f87420d0ee6
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Jul 14 14:20:36 2017 +0200

    tdf#108524 sw: handle sections inside tables in SwFrame::GetPrevSctLeaf()
    
    This addresses the sub-problem described in comment 12 of the bug, i.e.
    text frames are now moved to the first page from the second one when
    text frames are deleted on the first page.
    
    Change-Id: Ic0ede45381fb84b13d1ac02e4d1f39d817650616
    Reviewed-on: https://gerrit.libreoffice.org/39946
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index d69f682cb8fa..042ae9cee4a8 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -259,6 +259,7 @@ public:
     void testTableInSection();
     void testTableInNestedSection();
     void testLinesInSectionInTable();
+    void testLinesMoveBackwardsInSectionInTable();
 
     CPPUNIT_TEST_SUITE(SwUiWriterTest);
     CPPUNIT_TEST(testReplaceForward);
@@ -404,6 +405,7 @@ public:
     CPPUNIT_TEST(testTableInSection);
     CPPUNIT_TEST(testTableInNestedSection);
     CPPUNIT_TEST(testLinesInSectionInTable);
+    CPPUNIT_TEST(testLinesMoveBackwardsInSectionInTable);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -4983,6 +4985,33 @@ void SwUiWriterTest::testLinesInSectionInTable()
     assertXPath(pXmlDoc, "/root/page[2]/body/tab/row/cell/section", 1);
 }
 
+void SwUiWriterTest::testLinesMoveBackwardsInSectionInTable()
+{
+    // Assert that paragraph "4" is on page 1 and "5" is on page 2.
+    SwDoc* pDoc = createDoc("lines-in-section-in-table.odt");
+    xmlDocPtr pXmlDoc = parseLayoutDump();
+    assertXPath(pXmlDoc, "/root/page", 2);
+    sal_uInt32 nPara4Node = getXPath(pXmlDoc, "/root/page[1]/body/tab/row/cell[1]/section/txt[last()]", "txtNodeIndex").toUInt32();
+    CPPUNIT_ASSERT_EQUAL(OUString("4"), pDoc->GetNodes()[nPara4Node]->GetTextNode()->GetText());
+    sal_uInt32 nPara5Node = getXPath(pXmlDoc, "/root/page[2]/body/tab/row/cell[1]/section/txt[1]", "txtNodeIndex").toUInt32();
+    CPPUNIT_ASSERT_EQUAL(OUString("5"), pDoc->GetNodes()[nPara5Node]->GetTextNode()->GetText());
+
+    // Remove paragraph "4".
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+    while (pWrtShell->GetCursor()->GetNode().GetIndex() < nPara4Node)
+        pWrtShell->Down(/*bSelect=*/false);
+    pWrtShell->EndPara();
+    pWrtShell->Up(/*bSelect=*/true);
+    pWrtShell->DelLeft();
+
+    // Assert that paragraph "5" is now moved back to page 1 and is the last paragraph there.
+    discardDumpedLayout();
+    pXmlDoc = parseLayoutDump();
+    sal_uInt32 nPage1LastNode = getXPath(pXmlDoc, "/root/page[1]/body/tab/row/cell[1]/section/txt[last()]", "txtNodeIndex").toUInt32();
+    // This was "3", paragraph "4" was deleted, but "5" was not moved backwards from page 2.
+    CPPUNIT_ASSERT_EQUAL(OUString("5"), pDoc->GetNodes()[nPage1LastNode]->GetTextNode()->GetText());
+}
+
 void SwUiWriterTest::testTableInSection()
 {
     // The document has a section, containing a table that spans over 2 pages.
diff --git a/sw/source/core/layout/sectfrm.cxx b/sw/source/core/layout/sectfrm.cxx
index 08e3934ddf6f..23b547f64ec1 100644
--- a/sw/source/core/layout/sectfrm.cxx
+++ b/sw/source/core/layout/sectfrm.cxx
@@ -1726,11 +1726,24 @@ SwLayoutFrame *SwFrame::GetPrevSctLeaf()
     if( bJump )     // Did we skip a blank page?
         SwFlowFrame::SetMoveBwdJump( true );
 
+    SwSectionFrame *pSect = FindSctFrame();
+    if (!pCol && pSect && IsInTab() && !IsInTableInSection(this))
+    {
+        // We don't have a previous section yet, and we're in a
+        // section-in-table.
+        if (SwFlowFrame* pPrecede = pSect->GetPrecede())
+        {
+            // Our section has a precede, work with that.
+            if (pPrecede->GetFrame().IsLayoutFrame())
+                pCol = static_cast<SwLayoutFrame*>(&pPrecede->GetFrame());
+        }
+    }
+
     // Within sections in tables or section in headers/footers there can
     // be only one column change be made, one of the above shortcuts should
     // have applied, also when the section has a pPrev.
     // Now we even consider an empty column...
-    OSL_ENSURE( FindSctFrame(), "GetNextSctLeaf: Missing SectionFrame" );
+    OSL_ENSURE( pSect, "GetNextSctLeaf: Missing SectionFrame" );
     if( ( IsInTab() && !IsTabFrame() ) || FindFooterOrHeader() )
         return pCol;
 
@@ -1738,7 +1751,6 @@ SwLayoutFrame *SwFrame::GetPrevSctLeaf()
     // Precondition, which needs to be hold, is that the <this> frame can be
     // inside a table, but then the found section frame <pSect> is also inside
     // this table.
-    SwSectionFrame *pSect = FindSctFrame();
 
     // #i95698#
     // A table cell containing directly a section does not break - see lcl_FindSectionsInRow(..)


More information about the Libreoffice-commits mailing list