sw/qa/core/layout/flycnt.cxx | 19 +++++++++++++------ sw/source/core/txtnode/ndtxt.cxx | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-)
New commits: commit 83c300d00d25aa85381d91ed82b236ee8bb37a67 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Wed Dec 13 08:32:02 2023 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Thu Dec 14 09:45:42 2023 +0100 sw floattable: fix split of anchor text at para start The document has a floating table with some anchor text. If we hit enter at the end of the anchor text, the anchor text remains in the old text node and a new text node is inserted after it, still wrapping around the floating table. If you do the same at the start of the anchor text, then a new paragraph is inserted before the floating table, which is unexpected. The OOXML concept we try to model here is that a floating table is a table-in-fly that's followed by a paragraph that hosts the anchor text, so the anchor position of the floating table should never change. This behavior was even locked down in the testSplitFlyMoveMaster testcase, but there the motivation was to make sure the fly chain is consistent. Fix the problem by removing the special-casing in SwTextNode::SplitContentNode() for the "at para start" case that was added just to please the testcase. Instead update the test assert the bad 1 -> 4 -> 2 chain is not there, so it still covers the old fix but allows the new behavior. With this, the Word and Writer UI behaves the same when inserting a new para right after a floating table. The layout position problem of the empty text node (should be wrapped, is not) still needs fixing. (cherry picked from commit d852e27ed205c1a60de0979b80f3861bf93c44ae) Change-Id: Ib9a1f07eeb144ea929183cdc72a22bc23042fee1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160749 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/qa/core/layout/flycnt.cxx b/sw/qa/core/layout/flycnt.cxx index 6b84ca3fb16d..455012ea4948 100644 --- a/sw/qa/core/layout/flycnt.cxx +++ b/sw/qa/core/layout/flycnt.cxx @@ -1111,20 +1111,27 @@ CPPUNIT_TEST_FIXTURE(Test, testSplitFlyMoveMaster) // Given a document with a multi-page floating table on pages 1 -> 2 -> 3: createSwDoc("floattable-move-master.docx"); - // When adding an empty para before the table, so the table gets shifted to pages 2 -> 3: + // When adding an empty para at the start of the anchor text of the table: SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell(); pWrtShell->SttEndDoc(/*bStt=*/true); pWrtShell->Down(/*bSelect=*/false, /*nCount=*/4); pWrtShell->SplitNode(); - // Then make sure page 1 has no flys, page 2 and 3 has the split fly and no flys on page 4: + // Then make sure page the fly chain is pages 1 -> 2 -> 3, still: SwDoc* pDoc = getSwDoc(); SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout(); auto pPage1 = pLayout->Lower()->DynCastPageFrame(); CPPUNIT_ASSERT(pPage1); - // Without the accompanying fix in place, this test would have failed, the start of the fly was - // still on page 1 instead of page 2. - CPPUNIT_ASSERT(!pPage1->GetSortedObjs()); + // Without the accompanying fix in place, this test would have failed, the fly chain was pages 1 + // -> 4 -> 2. + CPPUNIT_ASSERT(pPage1->GetSortedObjs()); + CPPUNIT_ASSERT(pPage1->GetSortedObjs()); + SwSortedObjs& rPage1Objs = *pPage1->GetSortedObjs(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rPage1Objs.size()); + auto pPage1Fly = rPage1Objs[0]->DynCastFlyFrame()->DynCastFlyAtContentFrame(); + CPPUNIT_ASSERT(pPage1Fly); + CPPUNIT_ASSERT(!pPage1Fly->GetPrecede()); + CPPUNIT_ASSERT(pPage1Fly->HasFollow()); auto pPage2 = pPage1->GetNext()->DynCastPageFrame(); CPPUNIT_ASSERT(pPage2); CPPUNIT_ASSERT(pPage2->GetSortedObjs()); @@ -1132,7 +1139,7 @@ CPPUNIT_TEST_FIXTURE(Test, testSplitFlyMoveMaster) CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rPage2Objs.size()); auto pPage2Fly = rPage2Objs[0]->DynCastFlyFrame()->DynCastFlyAtContentFrame(); CPPUNIT_ASSERT(pPage2Fly); - CPPUNIT_ASSERT(!pPage2Fly->GetPrecede()); + CPPUNIT_ASSERT(pPage2Fly->GetPrecede()); CPPUNIT_ASSERT(pPage2Fly->HasFollow()); auto pPage3 = pPage2->GetNext()->DynCastPageFrame(); CPPUNIT_ASSERT(pPage3); diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx index 8cce58df0960..47bff5e08bac 100644 --- a/sw/source/core/txtnode/ndtxt.cxx +++ b/sw/source/core/txtnode/ndtxt.cxx @@ -464,7 +464,7 @@ SwTextNode *SwTextNode::SplitContentNode(const SwPosition & rPos, bool bSplitFly = false; std::optional<std::vector<SwFrameFormat*>> oFlys = sw::GetFlysAnchoredAt(GetDoc(), GetIndex()); - if (oFlys.has_value() && nSplitPos > 0) + if (oFlys.has_value()) { // See if one of the flys is a split fly. If so, we need to keep // the potentially split text frames unchanged and create a new