sw/qa/extras/layout/data/tdf170846_1.docx |binary
 sw/qa/extras/layout/data/tdf170846_2.docx |binary
 sw/qa/extras/layout/layout6.cxx           |   20 ++++++++++++++++++++
 sw/source/core/layout/tabfrm.cxx          |   21 +++++++++++++++++++++
 4 files changed, 41 insertions(+)

New commits:
commit 52172dbd3e290fb92fd8169803c6df5498990466
Author:     Mike Kaganski <[email protected]>
AuthorDate: Tue Feb 17 11:34:00 2026 +0500
Commit:     Mike Kaganski <[email protected]>
CommitDate: Wed Feb 18 12:07:38 2026 +0100

    tdf#170846: Use InsertMovedFwdFrame to move floating table forward
    
    Partially revert logic of commit 26aa5db06221ab940c65ecc27a2a52bf1ea0eb42
    (tdf#170477 follow-up: reimplement the fix by cleaning up code, 2026-01-26).
    It turned out problematic to completely avoid InsertMovedFwdFrame.
    But this change does not call InsertMovedFwdFrame after MoveFwd, as
    in the old code; it uses InsertMovedFwdFrame instead of MoveFwd.
    
    Change-Id: If54f6cf18320d76843bb3bfad888b729f50a7a7c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199513
    Reviewed-by: Mike Kaganski <[email protected]>
    Tested-by: Jenkins

diff --git a/sw/qa/extras/layout/data/tdf170846_1.docx 
b/sw/qa/extras/layout/data/tdf170846_1.docx
new file mode 100644
index 000000000000..b13782ba5514
Binary files /dev/null and b/sw/qa/extras/layout/data/tdf170846_1.docx differ
diff --git a/sw/qa/extras/layout/data/tdf170846_2.docx 
b/sw/qa/extras/layout/data/tdf170846_2.docx
new file mode 100644
index 000000000000..e7af0910978e
Binary files /dev/null and b/sw/qa/extras/layout/data/tdf170846_2.docx differ
diff --git a/sw/qa/extras/layout/layout6.cxx b/sw/qa/extras/layout/layout6.cxx
index b4c58304ada0..7b17efb8ff8c 100644
--- a/sw/qa/extras/layout/layout6.cxx
+++ b/sw/qa/extras/layout/layout6.cxx
@@ -2196,6 +2196,26 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter6, testTdf169999)
     }
 }
 
+CPPUNIT_TEST_FIXTURE(SwLayoutWriter6, testTdf170846_1)
+{
+    // In this document, the whole floating table must move to page 2
+    createSwDoc("tdf170846_1.docx");
+    xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+    // Without the fix, the next test failed:
+    assertXPath(pXmlDoc, "//page[1]//tab", 0); // No tables on page 1
+    assertXPath(pXmlDoc, "//page[2]//tab", 1); // One table on page 2
+}
+
+CPPUNIT_TEST_FIXTURE(SwLayoutWriter6, testTdf170846_2)
+{
+    // In this document, the whole floating table must move to page 2
+    createSwDoc("tdf170846_2.docx");
+    xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+    // Without the fix, the next test failed:
+    assertXPath(pXmlDoc, "//page[1]//tab", 0); // No tables on page 1
+    assertXPath(pXmlDoc, "//page[2]//tab", 3); // Three tables on page 2
+}
+
 } // end of anonymous namespace
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/core/layout/tabfrm.cxx b/sw/source/core/layout/tabfrm.cxx
index 23c8337b4e55..c61b39a6c02f 100644
--- a/sw/source/core/layout/tabfrm.cxx
+++ b/sw/source/core/layout/tabfrm.cxx
@@ -3287,6 +3287,27 @@ void SwTabFrame::MakeAll(vcl::RenderContext* 
pRenderContext)
                 {
                     // Don't try to move floating table forward. It's done 
elsewhere moving its fly.
                     bSkipMoveFwd = true;
+                    // Only limit the InsertMovedFwdFrame hack to non-split 
floating tables for now:
+                    // it seems that split tables don't need it.
+                    if (!IsFollow() && !HasFollow())
+                    {
+                        // This floating table doesn't fit on this page. 
Instead of the complex
+                        // MoveFwd sequence (split anchor, create follow fly, 
move table, destroy
+                        // old fly, merge anchor - which may oscillate), 
signal the anchor to move
+                        // forward. The fly will follow.
+                        SwTextFrame* pAnchor = 
pFlyFrame->FindAnchorCharFrame();
+                        if (pAnchor)
+                        {
+                            SwPageFrame* pPage = pAnchor->FindPageFrame();
+                            if (pPage)
+                            {
+                                
SwLayouter::InsertMovedFwdFrame(pPage->GetFormat()->GetDoc(),
+                                                                *pAnchor,
+                                                                
pPage->GetPhyPageNum() + 1);
+                                pAnchor->InvalidatePos();
+                            }
+                        }
+                    }
                 }
             }
             // don't make the effort to move fwd if its known

Reply via email to