sw/qa/core/layout/data/floattable-in-section.docx |binary
 sw/qa/core/layout/layact.cxx                      |   22 ++++++++++++++++++++++
 sw/qa/extras/uiwriter/uiwriter5.cxx               |    2 --
 sw/source/core/layout/layact.cxx                  |    6 +++++-
 sw/source/core/undo/untbl.cxx                     |   15 ++++++++++++++-
 5 files changed, 41 insertions(+), 4 deletions(-)

New commits:
commit 2f1cf8dd8b230f64ce9f64fc7761c425ebefaca2
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Thu Mar 14 12:14:28 2024 +0100
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Fri Mar 15 11:05:34 2024 +0100

    sw: fix ~SwIndexReg assert in testTdf149498
    
    The problem is that a SwNavigationMgr thingy has a cursor in one of the
    table cells, and the text node is moved to the undo nodes array in
    SwUndoTableCpyTable::AddBoxBefore() and deleted in
    SwUndoTableCpyTable::UndoImpl().
    
    SwUndoTableCpyTable needs to move the cursors out of the way because
    SwUndoDelete doesn't do it.
    
    Change-Id: I75e271c84a6624ffb0df151b171acb1e1f743928
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164807
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    (cherry picked from commit 873af30a36504751c6923d4235abd4de040e0001)

diff --git a/sw/qa/extras/uiwriter/uiwriter5.cxx 
b/sw/qa/extras/uiwriter/uiwriter5.cxx
index 285a3adb7c61..7b0b90b31759 100644
--- a/sw/qa/extras/uiwriter/uiwriter5.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter5.cxx
@@ -2807,7 +2807,6 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, testTdf156487)
     assertXPath(pXmlDoc, "/metafile/push/push/push/textarray/text", 1);
 }
 
-#ifndef DBG_UTIL
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, testTdf149498)
 {
     // load a table, and delete the first column with enabled change tracking:
@@ -2823,7 +2822,6 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, testTdf149498)
     // this would crash due to bookmark over cell boundary
     dispatchCommand(mxComponent, ".uno:Undo", {});
 }
-#endif
 
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, 
testTdf150673_RedlineTableColumnDeletionWithExport)
 {
diff --git a/sw/source/core/undo/untbl.cxx b/sw/source/core/undo/untbl.cxx
index 3092df0c2fd3..145a4ca12310 100644
--- a/sw/source/core/undo/untbl.cxx
+++ b/sw/source/core/undo/untbl.cxx
@@ -2592,11 +2592,17 @@ void SwUndoTableCpyTable::AddBoxBefore( const 
SwTableBox& rBox, bool bDelContent
     if( bDelContent )
     {
         SwNodeIndex aInsIdx( *rBox.GetSttNd(), 1 );
-        pDoc->GetNodes().MakeTextNode( aInsIdx.GetNode(), 
pDoc->GetDfltTextFormatColl() );
+        SwTextNode *const 
pNewNode(pDoc->GetNodes().MakeTextNode(aInsIdx.GetNode(), 
pDoc->GetDfltTextFormatColl()));
         SwPaM aPam( aInsIdx.GetNode(), *rBox.GetSttNd()->EndOfSectionNode() );
 
         if( !pDoc->getIDocumentRedlineAccess().IsRedlineOn() )
+        {
+            {   // move cursors to new node which precedes aPam
+                SwPosition const pos(*pNewNode, 0);
+                ::PaMCorrAbs(aPam, pos);
+            }
             pEntry->pUndo = std::make_unique<SwUndoDelete>(aPam, 
SwDeleteFlags::Default, true);
+        }
     }
 
     pEntry->pBoxNumAttr = std::make_unique<SfxItemSetFixed<
@@ -2620,6 +2626,13 @@ void SwUndoTableCpyTable::AddBoxAfter( const SwTableBox& 
rBox, const SwNodeIndex
         SwDoc* pDoc = rBox.GetFrameFormat()->GetDoc();
         DEBUG_REDLINE( pDoc )
 
+        {   // move cursors to first node which was inserted
+            SwPaM pam(SwNodeIndex(*rBox.GetSttNd(), 1));
+            assert(pam.GetPoint()->GetNode().IsTextNode());
+            pam.SetMark();
+            pam.Move(fnMoveForward, GoInContent);
+            ::PaMCorrAbs(pam, *pam.GetPoint());
+        }
         if( pDoc->getIDocumentRedlineAccess().IsRedlineOn() )
         {
             SwPosition aTmpPos( rIdx );
commit 34358b553343126a8f0b50d0111f794788be54db
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Fri Feb 23 09:12:17 2024 +0100
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Thu Mar 14 10:00:54 2024 +0100

    Related: tdf#158986 sw floattable: fix unexpected page break with sections
    
    Regression from commit c303981cfd95ce1c3881366023d5495ae2edce97
    (tdf#156724 sw: layout: fix tables not splitting due to footnotes
    differently, 2023-08-24), the floating table in the DOCX version of the
    bugdoc went from page 1 to page 2.
    
    It seems what happens is that the first page has 2 section frames, and
    we used to directly recalc the last lower of the first section frame,
    which triggered a recalc of the second section frame, so the table moved
    from page 2 to page 1 once the top of the second section frame was
    reduced (so the table could fit on page 1). But this direct recalc was
    removed because it caused problems for split tables and footnotes in
    tdf#156724.
    
    Fix the problem by conditionally restoring the OptCalc() call in
    SwLayAction::FormatLayout(): only do it for the last lower of section
    frames, which is enough for the DOCX version of tdf#158986, but it keeps
    the old tdf#156724 use-case working (the layout of that bugdoc doesn't
    modify with this change).
    
    The RTF version of the bugdoc (which was the originally reported
    problem) still needs more work, but that's hopefully not a layout
    problem but an RTF import one.
    
    Change-Id: I1134ec3a27aec8ee871b535d81dedf9d27bd6bd5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163805
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins
    (cherry picked from commit 397d72e582c725d162c7e0b819dc6c0bb62e42b0)

diff --git a/sw/qa/core/layout/data/floattable-in-section.docx 
b/sw/qa/core/layout/data/floattable-in-section.docx
index a0e9090bcccf..9aab264867f0 100644
Binary files a/sw/qa/core/layout/data/floattable-in-section.docx and 
b/sw/qa/core/layout/data/floattable-in-section.docx differ
diff --git a/sw/qa/core/layout/layact.cxx b/sw/qa/core/layout/layact.cxx
index 64262977f7fe..d967a6b1ed2d 100644
--- a/sw/qa/core/layout/layact.cxx
+++ b/sw/qa/core/layout/layact.cxx
@@ -73,6 +73,28 @@ CPPUNIT_TEST_FIXTURE(Test, testSplitFlyNextRowInvalidatePos)
     // i.e. row 2 has to be shifted down to 7390, but this didn't happen.
     CPPUNIT_ASSERT_GREATER(nOldRow2Top, nNewRow2Top);
 }
+
+CPPUNIT_TEST_FIXTURE(Test, testSplitFlyInSection)
+{
+    // Given a document with multiple sections, the 2nd section on page 1 has 
a one-page floating
+    // table:
+    createSwDoc("floattable-in-section.docx");
+
+    // When laying out that document:
+    SwDoc* pDoc = getSwDoc();
+    SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
+
+    // Then make sure the table is on page 1, not on page 2:
+    auto pPage1 = pLayout->Lower()->DynCastPageFrame();
+    CPPUNIT_ASSERT(pPage1);
+    // Without the fix in place, it would have failed, the table was on page 
2, not on page 1.
+    CPPUNIT_ASSERT(pPage1->GetSortedObjs());
+    SwSortedObjs& rPage1Objs = *pPage1->GetSortedObjs();
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rPage1Objs.size());
+    auto pPage2 = pPage1->GetNext()->DynCastPageFrame();
+    CPPUNIT_ASSERT(pPage2);
+    CPPUNIT_ASSERT(!pPage2->GetSortedObjs());
+}
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/layout/layact.cxx b/sw/source/core/layout/layact.cxx
index 747470129c96..7c62719c3667 100644
--- a/sw/source/core/layout/layact.cxx
+++ b/sw/source/core/layout/layact.cxx
@@ -1433,7 +1433,11 @@ bool SwLayAction::FormatLayout( OutputDevice 
*pRenderContext, SwLayoutFrame *pLa
                 PopFormatLayout();
             }
         }
-        // else: don't calc content frames any more
+        else if (pLay->IsSctFrame() && pLow->IsTextFrame() && pLow == 
pLay->GetLastLower())
+        {
+            // else: only calc the last text lower of sections
+            pLow->OptCalc();
+        }
 
         if ( IsAgain() )
             return false;

Reply via email to