sw/qa/extras/uiwriter/data/cross_reference_demo_bmk.odt |binary sw/qa/extras/uiwriter/uiwriter3.cxx | 75 ++++++++++++++++ sw/source/core/doc/DocumentContentOperationsManager.cxx | 15 ++- sw/source/core/doc/docglbl.cxx | 9 - 4 files changed, 90 insertions(+), 9 deletions(-)
New commits: commit 4bf04dea9afb30a9395e80b07a81d1908937ee8b Author: Michael Stahl <michael.st...@allotropia.de> AuthorDate: Fri Aug 27 14:38:18 2021 +0200 Commit: Michael Stahl <michael.st...@allotropia.de> CommitDate: Fri Aug 27 17:09:29 2021 +0200 tdf#128106 sw: copy bookmarks at start if whole node is copied The CrossRefHeadingBookmarks are always at index 0 so copy them if the selection also starts at index 0. This happens in SwDoc::SplitDoc() for the 2nd etc. chapter. Change-Id: I4765d497e65d3c8257f7eab59b8ba2088688967e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121147 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.st...@allotropia.de> diff --git a/sw/qa/extras/uiwriter/uiwriter3.cxx b/sw/qa/extras/uiwriter/uiwriter3.cxx index 64e3c8fb61cb..c283f3022803 100644 --- a/sw/qa/extras/uiwriter/uiwriter3.cxx +++ b/sw/qa/extras/uiwriter/uiwriter3.cxx @@ -2664,7 +2664,8 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf128106) CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_BOOKMARK), fields[1]->GetField()->GetSubType()); CPPUNIT_ASSERT( static_cast<SwGetRefField const*>(fields[1]->GetField())->IsRefToHeadingCrossRefBookmark()); - // CPPUNIT_ASSERT_EQUAL(OUString("Chapter 2"), static_cast<SwGetRefField const*>(fields[1]->GetField())->GetPar2()); + CPPUNIT_ASSERT_EQUAL(OUString("Chapter 2"), + static_cast<SwGetRefField const*>(fields[1]->GetField())->GetPar2()); CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_BOOKMARK), fields[2]->GetField()->GetSubType()); CPPUNIT_ASSERT_EQUAL(OUString("Bookmarkchapter1"), static_cast<SwGetRefField const*>(fields[2]->GetField())->GetSetRefName()); @@ -2683,7 +2684,8 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf128106) CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_BOOKMARK), fields[5]->GetField()->GetSubType()); CPPUNIT_ASSERT( static_cast<SwGetRefField const*>(fields[5]->GetField())->IsRefToHeadingCrossRefBookmark()); - // CPPUNIT_ASSERT_EQUAL(OUString("Chapter 2"), static_cast<SwGetRefField const*>(fields[5]->GetField())->GetPar2()); + CPPUNIT_ASSERT_EQUAL(OUString("Chapter 2"), + static_cast<SwGetRefField const*>(fields[5]->GetField())->GetPar2()); tempDir.EnableKillingFile(); } diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx b/sw/source/core/doc/DocumentContentOperationsManager.cxx index 35044a92a3bd..9af97d1c4626 100644 --- a/sw/source/core/doc/DocumentContentOperationsManager.cxx +++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx @@ -251,10 +251,21 @@ namespace sw const SwPosition& rMarkEnd = pMark->GetMarkEnd(); // only include marks that are in the range and not touching both start and end // - not for annotation or checkbox marks. + bool const isIncludeStart( + (rStt.nContent.GetIndex() == 0 // paragraph start selected? + // also: only if inserting at the start - cross reference + // marks require index to be 0, and there could be one + // on the target node already + && rCpyPam.nContent.GetIndex() == 0) + || rMarkStart != rStt); + bool const isIncludeEnd( + (rEnd.nNode.GetNode().IsTextNode() // paragraph end selected? + && rEnd.nContent.GetIndex() == rEnd.nNode.GetNode().GetTextNode()->Len()) + || rMarkEnd != rEnd); const bool bIsNotOnBoundary = pMark->IsExpanded() - ? (rMarkStart != rStt || rMarkEnd != rEnd) // rMarkStart != rMarkEnd - : (rMarkStart != rStt && rMarkEnd != rEnd); // rMarkStart == rMarkEnd + ? (isIncludeStart || isIncludeEnd) // rMarkStart != rMarkEnd + : (isIncludeStart && isIncludeEnd); // rMarkStart == rMarkEnd const IDocumentMarkAccess::MarkType aMarkType = IDocumentMarkAccess::GetType(*pMark); if ( rMarkStart >= rStt && rMarkEnd <= rEnd && ( bIsNotOnBoundary commit 3608de9a3647294361c64b923b1ae413ad9755df Author: Michael Stahl <michael.st...@allotropia.de> AuthorDate: Thu Aug 26 17:09:22 2021 +0200 Commit: Michael Stahl <michael.st...@allotropia.de> CommitDate: Fri Aug 27 17:09:13 2021 +0200 tdf#128106 sw: copy bookmarks in SwDoc::SplitDoc() Change-Id: Id35b8771b456b162ca653423d02788275a79443f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121146 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.st...@allotropia.de> diff --git a/sw/qa/extras/uiwriter/data/cross_reference_demo_bmk.odt b/sw/qa/extras/uiwriter/data/cross_reference_demo_bmk.odt new file mode 100644 index 000000000000..df8d95f912c4 Binary files /dev/null and b/sw/qa/extras/uiwriter/data/cross_reference_demo_bmk.odt differ diff --git a/sw/qa/extras/uiwriter/uiwriter3.cxx b/sw/qa/extras/uiwriter/uiwriter3.cxx index 72b715051cce..64e3c8fb61cb 100644 --- a/sw/qa/extras/uiwriter/uiwriter3.cxx +++ b/sw/qa/extras/uiwriter/uiwriter3.cxx @@ -28,6 +28,7 @@ #include <o3tl/safeint.hxx> #include <tools/json_writer.hxx> #include <unotools/streamwrap.hxx> +#include <sfx2/linkmgr.hxx> #include <fmtinfmt.hxx> #include <view.hxx> @@ -38,6 +39,9 @@ #include <dcontact.hxx> #include <svx/svdpage.hxx> #include <ndtxt.hxx> +#include <txtfld.hxx> +#include <IDocumentFieldsAccess.hxx> +#include <IDocumentLinksAdministration.hxx> #include <IDocumentRedlineAccess.hxx> namespace @@ -2615,6 +2619,75 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf136740) CPPUNIT_ASSERT_EQUAL(aNewCorrected, xTextDefaults->getPropertyValue("TabStopDistance")); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf128106) +{ + SwWrtShell* pWrtShell + = createSwDoc(DATA_DIRECTORY, "cross_reference_demo_bmk.odt")->GetDocShell()->GetWrtShell(); + + utl::TempFile tempDir(nullptr, true); + + const auto aPropertyValues = comphelper::InitPropertySequence( + { { "FileName", css::uno::Any(tempDir.GetURL() + "/test.odm") } }); + dispatchCommand(mxComponent, ".uno:NewGlobalDoc", aPropertyValues); + + // new document now! + mxComponent.set(pWrtShell->GetDoc()->GetDocShell()->GetModel()); + CPPUNIT_ASSERT(mxComponent.is()); + + SwDoc* const pMasterDoc(pWrtShell->GetDoc()); + CPPUNIT_ASSERT_EQUAL( + size_t(2), + pMasterDoc->getIDocumentLinksAdministration().GetLinkManager().GetLinks().size()); + // no way to set SwDocShell::m_nUpdateDocMode away from NO_UPDATE ? + // pMasterDoc->getIDocumentLinksAdministration().UpdateLinks(); + pMasterDoc->getIDocumentLinksAdministration().GetLinkManager().UpdateAllLinks(false, false, + nullptr); + // note: this has called SwGetRefFieldType::UpdateGetReferences() + SwFieldType const* const pType( + pMasterDoc->getIDocumentFieldsAccess().GetSysFieldType(SwFieldIds::GetRef)); + std::vector<SwFormatField*> fields; + pType->GatherFields(fields); + CPPUNIT_ASSERT_EQUAL(size_t(6), fields.size()); + std::sort(fields.begin(), fields.end(), [](auto const* const pA, auto const* const pB) { + SwTextField const* const pHintA(pA->GetTextField()); + SwTextField const* const pHintB(pB->GetTextField()); + // in this document: only 1 field per node + CPPUNIT_ASSERT(pA == pB || &pHintA->GetTextNode() != &pHintB->GetTextNode()); + return pHintA->GetTextNode().GetIndex() < pHintB->GetTextNode().GetIndex(); + }); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_BOOKMARK), fields[0]->GetField()->GetSubType()); + CPPUNIT_ASSERT_EQUAL(OUString("bookmarkchapter1_text"), + static_cast<SwGetRefField const*>(fields[0]->GetField())->GetSetRefName()); + CPPUNIT_ASSERT_EQUAL(OUString("Text"), + static_cast<SwGetRefField const*>(fields[0]->GetField()) + ->GetExpandedTextOfReferencedTextNode(*pWrtShell->GetLayout())); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_BOOKMARK), fields[1]->GetField()->GetSubType()); + CPPUNIT_ASSERT( + static_cast<SwGetRefField const*>(fields[1]->GetField())->IsRefToHeadingCrossRefBookmark()); + // CPPUNIT_ASSERT_EQUAL(OUString("Chapter 2"), static_cast<SwGetRefField const*>(fields[1]->GetField())->GetPar2()); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_BOOKMARK), fields[2]->GetField()->GetSubType()); + CPPUNIT_ASSERT_EQUAL(OUString("Bookmarkchapter1"), + static_cast<SwGetRefField const*>(fields[2]->GetField())->GetSetRefName()); + CPPUNIT_ASSERT_EQUAL(OUString("Chapter 1"), + static_cast<SwGetRefField const*>(fields[2]->GetField())->GetPar2()); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_BOOKMARK), fields[3]->GetField()->GetSubType()); + CPPUNIT_ASSERT_EQUAL(OUString("bookmarkchapter1_text"), + static_cast<SwGetRefField const*>(fields[3]->GetField())->GetSetRefName()); + CPPUNIT_ASSERT_EQUAL(OUString("Text"), + static_cast<SwGetRefField const*>(fields[3]->GetField())->GetPar2()); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_BOOKMARK), fields[4]->GetField()->GetSubType()); + CPPUNIT_ASSERT( + static_cast<SwGetRefField const*>(fields[4]->GetField())->IsRefToHeadingCrossRefBookmark()); + CPPUNIT_ASSERT_EQUAL(OUString("Chapter 1.1"), + static_cast<SwGetRefField const*>(fields[4]->GetField())->GetPar2()); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_BOOKMARK), fields[5]->GetField()->GetSubType()); + CPPUNIT_ASSERT( + static_cast<SwGetRefField const*>(fields[5]->GetField())->IsRefToHeadingCrossRefBookmark()); + // CPPUNIT_ASSERT_EQUAL(OUString("Chapter 2"), static_cast<SwGetRefField const*>(fields[5]->GetField())->GetPar2()); + + tempDir.EnableKillingFile(); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/doc/docglbl.cxx b/sw/source/core/doc/docglbl.cxx index 176a1a2a443c..a9ab35670ed1 100644 --- a/sw/source/core/doc/docglbl.cxx +++ b/sw/source/core/doc/docglbl.cxx @@ -307,7 +307,8 @@ bool SwDoc::SplitDoc( sal_uInt16 eDocType, const OUString& rPath, bool bOutline, SwNodeRange aRg( *pStartNd, 0, aEndIdx.GetNode() ); SwNodeIndex aTmpIdx( pDoc->GetNodes().GetEndOfContent() ); - GetNodes().Copy_( aRg, aTmpIdx, false ); + GetDocumentContentOperationsManager().CopyWithFlyInFly( + aRg, aTmpIdx, nullptr, false, false); // Delete the initial TextNode SwNodeIndex aIdx( pDoc->GetNodes().GetEndOfExtras(), 2 ); @@ -315,12 +316,6 @@ bool SwDoc::SplitDoc( sal_uInt16 eDocType, const OUString& rPath, bool bOutline, pDoc->GetNodes().GetEndOfContent().GetIndex() ) pDoc->GetNodes().Delete( aIdx ); - // All Flys in the section - GetDocumentContentOperationsManager().CopyFlyInFlyImpl(aRg, nullptr, aIdx); - - // And what's with all the Bookmarks? - // ????? - utl::TempFile aTempFile2(sLeading, true, &sExt, &sPath); sFileName = aTempFile2.GetURL(); SfxMedium* pTmpMed = new SfxMedium( sFileName,