sw/qa/extras/ooxmlexport/ooxmlexport10.cxx | 6 +++++ sw/source/core/doc/DocumentContentOperationsManager.cxx | 18 ++++++++++++---- sw/source/core/inc/DocumentContentOperationsManager.hxx | 3 +- 3 files changed, 22 insertions(+), 5 deletions(-)
New commits: commit 4daeb21a5f533144fd6b3bc397a98f37e5b1dd4c Author: Justin Luth <justin.l...@collabora.com> AuthorDate: Fri Mar 24 20:45:29 2023 -0400 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Mon Mar 27 21:12:42 2023 +0000 sw CopyBookmarks: ensure that Move copies can rename The problem was that a reference to the bookmark name was failing - since the move was adding a "Copy 1" at the end. That rename line is very deceptive because AFAICS it fails every time. I'm going to look at removing it in a followup commit. Two other unit tests also found with make sw.check -tdf149089.docx -tdf149507.docx but they also didn't have references to the bookmark to visually notice. make CppunitTest_sw_ooxmlexport10 CPPUNIT_TEST_NAME=testTdf92157 Change-Id: Idd695ec4a89057b28a68bc051b73f17fd4c3de56 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149574 Tested-by: Jenkins Reviewed-by: Justin Luth <jl...@mail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx index 95d29b40dec6..60f7eb57b711 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx @@ -1170,6 +1170,12 @@ DECLARE_OOXMLEXPORT_TEST(testTdf95775, "tdf95775.docx") DECLARE_OOXMLEXPORT_TEST(testTdf92157, "tdf92157.docx") { // A graphic with dimensions 0,0 should not fail on load + + // Additionally, the bookmark names should not change (they got a "1" appended when copied) + uno::Reference<text::XBookmarksSupplier> xBookmarksSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XNameAccess> xBookmarksByName = xBookmarksSupplier->getBookmarks(); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("referentiegegevens")); + CPPUNIT_ASSERT(xBookmarksByName->hasByName("referentiegegevens_bk")); } DECLARE_OOXMLEXPORT_TEST(testTdf97417, "section_break_numbering.docx") diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx b/sw/source/core/doc/DocumentContentOperationsManager.cxx index 39c54d4c5668..01f1000eee7b 100644 --- a/sw/source/core/doc/DocumentContentOperationsManager.cxx +++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx @@ -232,7 +232,7 @@ namespace namespace sw { // TODO: use SaveBookmark (from DelBookmarks) - void CopyBookmarks(const SwPaM& rPam, const SwPosition& rCpyPam) + void CopyBookmarks(const SwPaM& rPam, const SwPosition& rCpyPam, SwCopyFlags flags) { const SwDoc& rSrcDoc = rPam.GetDoc(); SwDoc& rDestDoc = rCpyPam.GetDoc(); @@ -295,9 +295,19 @@ namespace sw lcl_SetCpyPos(pMark->GetOtherMarkPos(), rStt, *pCpyStt, *aTmpPam.GetMark(), nDelCount); } + OUString sRequestedName = pMark->GetName(); + if (flags & SwCopyFlags::IsMoveToFly) + { + assert(&rSrcDoc == &rDestDoc); + // Ensure the name can be given to NewMark, since this is ultimately a move + auto pSoonToBeDeletedMark = const_cast<sw::mark::IMark*>(pMark); + rDestDoc.getIDocumentMarkAccess()->renameMark(pSoonToBeDeletedMark, + sRequestedName + "COPY_IS_MOVE"); + } + ::sw::mark::IMark* const pNewMark = rDestDoc.getIDocumentMarkAccess()->makeMark( aTmpPam, - pMark->GetName(), + sRequestedName, IDocumentMarkAccess::GetType(*pMark), ::sw::mark::InsertMode::CopyText); // Explicitly try to get exactly the same name as in the source @@ -308,7 +318,7 @@ namespace sw || IDocumentMarkAccess::GetType(*pMark) == IDocumentMarkAccess::MarkType::CROSSREF_HEADING_BOOKMARK); continue; // can't insert duplicate cross reference mark } - rDestDoc.getIDocumentMarkAccess()->renameMark(pNewMark, pMark->GetName()); + rDestDoc.getIDocumentMarkAccess()->renameMark(pNewMark, sRequestedName); // copying additional attributes for bookmarks or fieldmarks ::sw::mark::IBookmark* const pNewBookmark = @@ -3664,7 +3674,7 @@ void DocumentContentOperationsManager::CopyWithFlyInFly( targetPos = pCopiedPaM->second; } - sw::CopyBookmarks(pCopiedPaM ? pCopiedPaM->first : aRgTmp, targetPos); + sw::CopyBookmarks(pCopiedPaM ? pCopiedPaM->first : aRgTmp, targetPos, flags); } if (rRg.aStart != rRg.aEnd) diff --git a/sw/source/core/inc/DocumentContentOperationsManager.hxx b/sw/source/core/inc/DocumentContentOperationsManager.hxx index e961df8cf8c7..6d2d9a5fa6ea 100644 --- a/sw/source/core/inc/DocumentContentOperationsManager.hxx +++ b/sw/source/core/inc/DocumentContentOperationsManager.hxx @@ -179,7 +179,8 @@ private: }; -void CopyBookmarks(const SwPaM& rPam, const SwPosition& rTarget); +void CopyBookmarks(const SwPaM& rPam, const SwPosition& rTarget, + SwCopyFlags flags = SwCopyFlags::Default); void CalcBreaks(std::vector<std::pair<SwNodeOffset, sal_Int32>> & rBreaks, SwPaM const & rPam, bool const isOnlyFieldmarks = false);