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 <vmiklos@collabora.com>
This commit is contained in:
Miklos Vajna
2026-01-29 14:28:07 +01:00
parent 3227c095fb
commit a72506da82
3 changed files with 30 additions and 0 deletions
@@ -293,6 +293,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:
@@ -2000,7 +2000,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)