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 ea0e390f5d582f8669ccd9a7354dd6570a751918
Author:     Miklos Vajna <[email protected]>
AuthorDate: Thu Jan 29 08:37:37 2026 +0100
Commit:     Caolán McNamara <[email protected]>
CommitDate: Thu Jan 29 11:30:11 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/+/198335
    Reviewed-by: Caolán McNamara <[email protected]>
    Tested-by: Jenkins CollaboraOffice <[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 cb16ac8a1e34..64c59c2cfd29 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport25.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport25.cxx
@@ -238,6 +238,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(mpFilter);
+
+    // 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 67a7884ea2b2..bc39dab918ea 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -2005,7 +2005,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