sw/qa/core/txtnode/data/comment.docx |binary
 sw/qa/core/txtnode/txtnode.cxx       |   33 +++++++++++++++++++++++++++++++++
 sw/source/core/txtnode/thints.cxx    |   10 ++++++++--
 3 files changed, 41 insertions(+), 2 deletions(-)

New commits:
commit 212718852a089c81811dcadabf277673fe06b682
Author:     Gökay Şatır <[email protected]>
AuthorDate: Fri May 30 15:51:23 2025 +0300
Commit:     Xisco Fauli <[email protected]>
CommitDate: Wed Jun 18 10:01:20 2025 +0200

    cool#12147: Revive previous copy behaviour on load.
    
    We added some improvements for copying the comments along with their 
replies before. Which is done with commit:
    * https://gerrit.libreoffice.org/c/core/+/177396
    
    But it somehow broke docx export, when there are comments in file.
    
    TextNodes are copied while loading the document. And the error seems to 
occur in this phase.
    This commit keeps the previous behaviour while loading the file.
    
    Signed-off-by: Gökay Şatır <[email protected]>
    Change-Id: I80c343cbc4886f4277e38ff23553195cc8b1acfb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186043
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Miklos Vajna <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186605
    Tested-by: Jenkins
    (cherry picked from commit e2d32fec07396a75754a8979db6108213df11114)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186620
    Reviewed-by: Xisco Fauli <[email protected]>

diff --git a/sw/qa/core/txtnode/data/comment.docx 
b/sw/qa/core/txtnode/data/comment.docx
new file mode 100644
index 000000000000..c02003706ad2
Binary files /dev/null and b/sw/qa/core/txtnode/data/comment.docx differ
diff --git a/sw/qa/core/txtnode/txtnode.cxx b/sw/qa/core/txtnode/txtnode.cxx
index c4fee7887228..3d9eeab9afb4 100644
--- a/sw/qa/core/txtnode/txtnode.cxx
+++ b/sw/qa/core/txtnode/txtnode.cxx
@@ -44,6 +44,8 @@
 #include <PostItMgr.hxx>
 #include <AnnotationWin.hxx>
 #include <docufld.hxx>
+#include <IDocumentFieldsAccess.hxx>
+#include <MarkManager.hxx>
 
 /// Covers sw/source/core/txtnode/ fixes.
 class SwCoreTxtnodeTest : public SwModelTestBase
@@ -612,6 +614,37 @@ CPPUNIT_TEST_FIXTURE(SwCoreTxtnodeTest, 
testNodeSplitStyleListLevel)
     CPPUNIT_ASSERT_EQUAL(4, pPrevious->GetAttrListLevel());
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreTxtnodeTest, testDOCXCommentImport)
+{
+    // Given a DOCX file with a comment in it:
+    // When loading that file:
+    createSwDoc("comment.docx");
+
+    // Then make sure that the postit field has a name that matches the name 
of an annotation mark:
+    SwDoc* pDoc = getSwDoc();
+    const SwFieldTypes* pFieldTypes = 
pDoc->getIDocumentFieldsAccess().GetFieldTypes();
+    const SwFieldType* pPostitFieldType = nullptr;
+    for (const auto& pFieldType : *pFieldTypes)
+    {
+        if (pFieldType->Which() == SwFieldIds::Postit)
+        {
+            pPostitFieldType = pFieldType.get();
+            break;
+        }
+    }
+    CPPUNIT_ASSERT(pPostitFieldType);
+    std::vector<SwFormatField*> aFormatPostits;
+    pPostitFieldType->GatherFields(aFormatPostits);
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aFormatPostits.size());
+    const SwFormatField* pFormatPostit = aFormatPostits[0];
+    auto pPostit = static_cast<const 
SwPostItField*>(pFormatPostit->GetField());
+    IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
+    auto it = pMarkAccess->findAnnotationMark(pPostit->GetName());
+    // Without the accompanying fix in place, this test would have failed, 
there were no annotation
+    // marks with the name of pPostit.
+    CPPUNIT_ASSERT(it != pMarkAccess->getAnnotationMarksEnd());
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/txtnode/thints.cxx 
b/sw/source/core/txtnode/thints.cxx
index a081ad27ee4a..d806b2737e47 100644
--- a/sw/source/core/txtnode/thints.cxx
+++ b/sw/source/core/txtnode/thints.cxx
@@ -1103,8 +1103,14 @@ SwTextAttr* MakeTextAttr(
                 // when the annotation mark is created and inserted into the 
document.
                 auto& pField = const_cast<SwPostItField&>(dynamic_cast<const 
SwPostItField&>(*(pNew->GetFormatField().GetField())));
 
-                // We set the name here to make the object referenceable.
-                
pField.SetName(sw::mark::MarkBase::GenerateNewName(u"__Annotation__"));
+                if (!rDoc.IsInWriterfilterImport())
+                {
+                    // We set the name here to make the object referencable.
+                    
pField.SetName(sw::mark::MarkBase::GenerateNewName(u"__Annotation__"));
+                }
+                else // Keep the previous behaviour while loading the file.
+                    pField.SetName(SwMarkName());
+
                 pField.SetPostItId();
             }
         }

Reply via email to