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 f08bd56cff961cb53f0c2b695513781bbc3e91e4
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Fri Mar 24 20:45:29 2023 -0400
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Fri Mar 31 06:02:25 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>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149641
    Tested-by: Justin Luth <jl...@mail.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149766
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>

diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
index cfeafa71170b..937beb548e6d 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
@@ -1177,6 +1177,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 c368ada50194..9e383db67190 100644
--- a/sw/source/core/doc/DocumentContentOperationsManager.cxx
+++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx
@@ -230,7 +230,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();
@@ -293,9 +293,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
@@ -306,7 +316,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 =
@@ -3683,7 +3693,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 5434e43f2a9c..32663cafd2fa 100644
--- a/sw/source/core/inc/DocumentContentOperationsManager.hxx
+++ b/sw/source/core/inc/DocumentContentOperationsManager.hxx
@@ -185,7 +185,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);

Reply via email to