summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2021-12-08 10:11:06 +0100
committerLászló Németh <nemeth@numbertext.org>2021-12-08 12:40:51 +0100
commit76784f2dbf6d8641cfb6bf5d24e37521d6c806df (patch)
tree7d53cc2ea54e28d9c1b2db4769a8552324eeb0f7
parentRelated: tdf#132466 Relative address parsing needs current position (diff)
downloadcore-76784f2dbf6d8641cfb6bf5d24e37521d6c806df.tar.gz
core-76784f2dbf6d8641cfb6bf5d24e37521d6c806df.zip
tdf#107292: ODT import: fix order of deletions at same position
Tracked deletions at the same position were loaded in reverse order, resulting broken text content. Note: FODT format is not applicable for the unit test document, because it's not affected by the problem. Change-Id: Id13f8d23ae5964cbf82095a3d1ce2f6c9fdd59e1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126529 Tested-by: Jenkins Reviewed-by: László Németh <nemeth@numbertext.org>
-rw-r--r--sw/qa/extras/odfexport/data/tdf107292.odtbin0 -> 9921 bytes
-rw-r--r--sw/qa/extras/odfexport/odfexport.cxx11
-rw-r--r--sw/source/filter/xml/XMLRedlineImportHelper.cxx21
3 files changed, 32 insertions, 0 deletions
diff --git a/sw/qa/extras/odfexport/data/tdf107292.odt b/sw/qa/extras/odfexport/data/tdf107292.odt
new file mode 100644
index 000000000000..f35da387f964
--- /dev/null
+++ b/sw/qa/extras/odfexport/data/tdf107292.odt
Binary files differ
diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx
index f7ed88cd04a9..d3fe6465b4d4 100644
--- a/sw/qa/extras/odfexport/odfexport.cxx
+++ b/sw/qa/extras/odfexport/odfexport.cxx
@@ -561,6 +561,17 @@ DECLARE_ODFEXPORT_TEST(testredlineTextFrame, "redlineTextFrame.odt")
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
}
+DECLARE_ODFEXPORT_TEST(testTdf107292, "tdf107292.odt")
+{
+ // tracked deletions at the same position were loaded in reverse order
+ CPPUNIT_ASSERT_EQUAL(1, getPages());
+
+ // Without this fix in place, this test would have failed with
+ // - Expected: Lorem ipsum dolor sit...
+ // - Actual : dolor ipsumLorem sit...
+ CPPUNIT_ASSERT_EQUAL(OUString("Lorem ipsum dolor sit..."), getParagraph(1)->getString());
+}
+
DECLARE_ODFEXPORT_TEST(testTdf140437, "tdf140437.odt")
{
// Without the fix in place, the document would have failed to load
diff --git a/sw/source/filter/xml/XMLRedlineImportHelper.cxx b/sw/source/filter/xml/XMLRedlineImportHelper.cxx
index 5e289bb7648f..2edaf23cf847 100644
--- a/sw/source/filter/xml/XMLRedlineImportHelper.cxx
+++ b/sw/source/filter/xml/XMLRedlineImportHelper.cxx
@@ -653,6 +653,22 @@ void XMLRedlineImportHelper::InsertIntoDocument(RedlineInfo* pRedlineInfo)
new SwRangeRedline( pRedlineData, *aPaM.GetPoint(),
!pRedlineInfo->bMergeLastParagraph );
+ // tdf#107292 fix order of delete redlines at the same position by removing
+ // the already inserted redlines temporarily and inserting them back in reverse
+ // order after inserting pRedline
+ std::vector<const SwRangeRedline*> aSwapRedlines;
+ if ( RedlineType::Delete == pRedlineInfo->eType )
+ {
+ SwRedlineTable::size_type n = 0;
+ while ( const SwRangeRedline* pRedline2 =
+ pDoc->getIDocumentRedlineAccess().GetRedline( *pRedline->Start(), &n ) )
+ {
+ SwRedlineTable& aRedlineTable = pDoc->getIDocumentRedlineAccess().GetRedlineTable();
+ aSwapRedlines.push_back(pRedline2);
+ aRedlineTable.Remove(n);
+ }
+ }
+
// set mark
if( aPaM.HasMark() )
{
@@ -674,6 +690,11 @@ void XMLRedlineImportHelper::InsertIntoDocument(RedlineInfo* pRedlineInfo)
// set redline mode (without doing the associated book-keeping)
pDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern(RedlineFlags::On);
pDoc->getIDocumentRedlineAccess().AppendRedline(pRedline, false);
+
+ // restore the correct order of the delete redlines at the same position
+ for (auto i = aSwapRedlines.rbegin(); i != aSwapRedlines.rend(); ++i)
+ pDoc->getIDocumentRedlineAccess().AppendRedline(const_cast<SwRangeRedline*>(*i), false);
+
pDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern(RedlineFlags::NONE);
}
}