sw/qa/extras/ooxmlexport/ooxmlexport12.cxx    |    2 -
 sw/source/core/doc/DocumentRedlineManager.cxx |   30 ++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 1 deletion(-)

New commits:
commit c5f7619d6eebe478332ae4dcb27fde85df6278a9
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Mon Feb 24 16:02:33 2025 +0100
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Tue Feb 25 10:51:36 2025 +0100

    tdf#165322 sw: GetRedline() binary search doesn't work with overlaps
    
    Change-Id: I6d7a271eb96f55abdd6d53a153b277083868109b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182117
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    Tested-by: Jenkins

diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx
index 902d2f5f33eb..17b09796db41 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx
@@ -1608,7 +1608,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf125546)
     loadAndSave("tdf125546.docx");
     xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr);
     // compress redlines (it was 15)
-    assertXPath(pXmlDoc, "//w:rPrChange", 2);
+    assertXPath(pXmlDoc, "//w:rPrChange", 3);
 }
 
 CPPUNIT_TEST_FIXTURE(Test, testLabelWidthAndPosition_Left_FirstLineIndent)
diff --git a/sw/source/core/doc/DocumentRedlineManager.cxx 
b/sw/source/core/doc/DocumentRedlineManager.cxx
index 22cbdedb9ef0..1b658826db39 100644
--- a/sw/source/core/doc/DocumentRedlineManager.cxx
+++ b/sw/source/core/doc/DocumentRedlineManager.cxx
@@ -2968,6 +2968,36 @@ bool DocumentRedlineManager::HasRedline( const SwPaM& 
rPam, RedlineType nType, b
 const SwRangeRedline* DocumentRedlineManager::GetRedline( const SwPosition& 
rPos,
                                     SwRedlineTable::size_type* pFndPos ) const
 {
+    if (maRedlineTable.HasOverlappingElements())
+    {
+        for (auto it = maRedlineTable.begin(), itEnd = maRedlineTable.end(); 
it != itEnd; ++it)
+        {
+            auto [pStart, pEnd] = (**it).StartEnd();
+            if (rPos < *pStart)
+            {
+                if (pFndPos)
+                {
+                    *pFndPos = std::distance(maRedlineTable.begin(), it);
+                }
+                return nullptr;
+            }
+            if (pEnd == pStart
+                    ? *pStart == rPos
+                    : (*pStart <= rPos && rPos < *pEnd))
+            {
+                if (pFndPos)
+                {
+                    *pFndPos = std::distance(maRedlineTable.begin(), it);
+                }
+                return *it;
+            }
+        }
+        if (pFndPos)
+        {
+            *pFndPos = maRedlineTable.size();
+        }
+        return nullptr;
+    }
     SwRedlineTable::size_type nO = maRedlineTable.size(), nM, nU = 0;
     if( nO > 0 )
     {

Reply via email to