sw/qa/extras/ooxmlexport/data/redline-range-comment.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport25.cxx               |   17 +++++++++++++++
 sw/source/filter/ww8/docxattributeoutput.cxx             |   13 +++++++++++
 3 files changed, 30 insertions(+)

New commits:
commit 4a7ea75108c842e95af769cd246fccf5064fd1f7
Author:     Miklos Vajna <[email protected]>
AuthorDate: Thu Jan 29 08:37:37 2026 +0100
Commit:     Adolfo Jayme Barrientos <[email protected]>
CommitDate: Mon Feb 2 15:21:23 2026 +0100

    cool#13988 DOCX export: fix missing delete flag on deleted comments with 
ranges
    
    Load the bugdoc, see that the comment is marked as deleted (is anchored
    inside a delete redline), save, reload, the comment is no longer
    deleted.
    
    This is because we write redline start/end around DOCX "runs", and the
    comment reference dummy character is one such dummy run. So unless
    explicit redline markup is written, comments (their comment reference)
    is not inside a redline.
    
    Fix this by checking if we'll write comment references (part of comment
    end) in DocxAttributeOutput::EndRun(). If we're inside a delete, write
    the delete redline markup around the comment reference, too.
    
    Doing the same for inserts would make sense, but then first we would
    need to tweak Writer's UI to insert new comments outside redlines,
    otherwise UITest_writer_tests7's
    tdf90401.tdf90401.test_tdf142902_remove_personal_info_in_DOCX would
    break.
    
    Change-Id: I8d6db05c8a9fd1d5e1e619843967e3f21fb43e59
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/198353
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <[email protected]>
    (cherry picked from commit a72506da82d2e0334e23a8c3c1cd07282fdd7ca3)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/198364
    Reviewed-by: Adolfo Jayme Barrientos <[email protected]>

diff --git a/sw/qa/extras/ooxmlexport/data/redline-range-comment.docx 
b/sw/qa/extras/ooxmlexport/data/redline-range-comment.docx
new file mode 100644
index 000000000000..1110971401f5
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/redline-range-comment.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport25.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport25.cxx
index 407daf14dc9a..4649e916b556 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport25.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport25.cxx
@@ -290,6 +290,23 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf167082)
     CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"), aStyleName);
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testRangeCommentInDeleteDocxExport)
+{
+    // Given a document with a comment that is inside a delete redline:
+    createSwDoc("redline-range-comment.docx");
+
+    // When exporting that to DOCX:
+    save(TestFilter::DOCX);
+
+    // Then make sure that the comment reference is inside the delete redline:
+    xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr);
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 1
+    // - Actual  : 0
+    // i.e. the comment anchor was outside the redline.
+    CPPUNIT_ASSERT_EQUAL(1, countXPathNodes(pXmlDoc, 
"//w:del/w:r/w:commentReference"));
+}
+
 CPPUNIT_TEST_FIXTURE(Test, testFloatingTableAnchorPosExport)
 {
     // Given a document with two floating tables after each other:
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index 286ce3a077da..79dc73574236 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -1999,7 +1999,20 @@ void DocxAttributeOutput::EndRun(const SwTextNode* 
pNode, sal_Int32 nPos, sal_In
     DoWriteBookmarksStart(m_rBookmarksStart, m_pMoveRedlineData);
     DoWriteBookmarksEnd(m_rBookmarksEnd, false, false); // Write non-moverange 
bookmarks
     DoWritePermissionsStart();
+
+    // Surround annotation references with redline start/end markup if we're 
inside a delete.
+    bool bHasAnnotationMarkReferencesInDel = !m_rAnnotationMarksEnd.empty() && 
m_pRedlineData
+                                             && m_pRedlineData->GetType() == 
RedlineType::Delete;
+    if (bHasAnnotationMarkReferencesInDel)
+    {
+        StartRedline(m_pRedlineData, bLastRun);
+    }
     DoWriteAnnotationMarks();
+    if (bHasAnnotationMarkReferencesInDel)
+    {
+        EndRedline(m_pRedlineData, bLastRun);
+    }
+
     // if there is some redlining in the document, output it
     bool bSkipRedline = false;
     if (nLen == 1)

Reply via email to