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 f3ab289b358fd2e7698465dcd6353f22b0278888
Author:     Gökay Şatır <gokaysa...@gmail.com>
AuthorDate: Fri May 30 15:51:23 2025 +0300
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Fri Jun 13 17:02:30 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 <gokaysa...@gmail.com>
    Change-Id: I80c343cbc4886f4277e38ff23553195cc8b1acfb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186043
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

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 dccf6d77a487..fbf420f018ac 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
@@ -609,6 +611,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 77c1a50ba628..df2fc9e593a6 100644
--- a/sw/source/core/txtnode/thints.cxx
+++ b/sw/source/core/txtnode/thints.cxx
@@ -1094,8 +1094,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 referencable.
-                
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(OUString());
+
                 pField.SetPostItId();
             }
         }

Reply via email to