diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2023-12-13 08:32:02 +0100 |
---|---|---|
committer | Caolán McNamara <caolan.mcnamara@collabora.com> | 2023-12-14 10:21:53 +0100 |
commit | f6f27ac1ef6d0fcc895bd5ff5f36c5857eb37109 (patch) | |
tree | 17aa5850f7c13cb10ae21900588cc2871eb0aafa | |
parent | 9a946645c8029bc6382d8e455b76430d4e4bc37f (diff) |
sw floattable: fix split of anchor text at para startcp-23.05.6-3
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/+/160756
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Tested-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
-rw-r--r-- | sw/qa/core/layout/flycnt.cxx | 19 | ||||
-rw-r--r-- | sw/source/core/txtnode/ndtxt.cxx | 2 |
2 files changed, 14 insertions, 7 deletions
diff --git a/sw/qa/core/layout/flycnt.cxx b/sw/qa/core/layout/flycnt.cxx index 9fb2e2ed0f4f..013718fd52c1 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 ff05143b0052..1bad6a89d011 100644 --- a/sw/source/core/txtnode/ndtxt.cxx +++ b/sw/source/core/txtnode/ndtxt.cxx @@ -463,7 +463,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 |