sw/qa/extras/layout/layout2.cxx  |   13 +++++++++++++
 sw/source/core/text/redlnitr.cxx |   10 ++++++++++
 2 files changed, 23 insertions(+)

New commits:
commit c73a02e5da639a1372ee9f00237ba0d27b7110d5
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Wed Feb 19 16:20:56 2025 +0100
Commit:     Adolfo Jayme Barrientos <fit...@ubuntu.com>
CommitDate: Wed Feb 26 13:20:51 2025 +0100

    sw: fix bug with redline following fieldmark or hidden break
    
    It is now possible for HideIterator to move to another node without a
    redline being involved, but if this happens and there was no redline on
    the previous node, GetRedlinePos() had already returned
    SwRedlineTable::npos and now no redlines can be found in the new node.
    
    (regression from commit 657de5fba12b0e9afcdee361654d2a2d0dbd7311)
    
    Change-Id: I536b2660c97501be896203403cdd5e2f2015e816
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181946
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    (cherry picked from commit 21bc6e075d8b004bce7bf7d9305f5fdcff2df24d)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182192
    Reviewed-by: Adolfo Jayme Barrientos <fit...@ubuntu.com>

diff --git a/sw/qa/extras/layout/layout2.cxx b/sw/qa/extras/layout/layout2.cxx
index ae4c53826379..a9cd34f17432 100644
--- a/sw/qa/extras/layout/layout2.cxx
+++ b/sw/qa/extras/layout/layout2.cxx
@@ -978,6 +978,19 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testHiddenParaProps)
     CPPUNIT_ASSERT_EQUAL(
         SvxAdjust::Left,
         
pTextFrame->GetTextNodeForParaProps()->GetSwAttrSet().Get(RES_PARATR_ADJUST).GetAdjust());
+
+    dispatchCommand(mxComponent, u".uno:ShowTrackedChanges"_ustr, {});
+
+    pTextFrame = dynamic_cast<SwTextFrame*>(pBody->GetLower());
+    for (int i = 0; i < 18; ++i)
+    {
+        pTextFrame = dynamic_cast<SwTextFrame*>(pTextFrame->GetNext());
+    }
+    // the problem was that this redline (following hidden) wasn't merged
+    CPPUNIT_ASSERT_EQUAL(u"10 visible, hidden-merge, visible, delete-merge, 
visible"_ustr,
+                         pTextFrame->GetText());
+    pTextFrame = dynamic_cast<SwTextFrame*>(pTextFrame->GetNext());
+    CPPUNIT_ASSERT_EQUAL(u"abcdefghi"_ustr, pTextFrame->GetText());
 }
 
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testTdf151954)
diff --git a/sw/source/core/text/redlnitr.cxx b/sw/source/core/text/redlnitr.cxx
index 7de60b24c406..60545116aa21 100644
--- a/sw/source/core/text/redlnitr.cxx
+++ b/sw/source/core/text/redlnitr.cxx
@@ -78,6 +78,7 @@ private:
     /// current start/end pair
     SwPosition const* m_pStartPos;
     SwPosition const* m_pEndPos;
+    SwNode const* m_pCurrentRedlineNode;
 
 public:
     SwPosition const* GetStartPos() const { return m_pStartPos; }
@@ -95,6 +96,7 @@ public:
         , m_RedlineIndex(isHideRedlines ? m_rIDRA.GetRedlinePos(rTextNode, 
RedlineType::Any) : SwRedlineTable::npos)
         , m_pStartPos(nullptr)
         , m_pEndPos(&m_Start)
+        , m_pCurrentRedlineNode(&rTextNode)
     {
     }
 
@@ -108,6 +110,14 @@ public:
         assert(m_pEndPos);
         if (m_isHideRedlines)
         {
+            // GetRedlinePos() returns npos if there is no redline on the
+            // node but something else could have merged nodes so search again!
+            if (m_RedlineIndex == SwRedlineTable::npos
+                && &m_pEndPos->GetNode() != m_pCurrentRedlineNode)
+            {
+                m_RedlineIndex = m_rIDRA.GetRedlinePos(m_pEndPos->GetNode(), 
RedlineType::Any);
+                m_pCurrentRedlineNode = &m_pEndPos->GetNode();
+            }
             // position on current or next redline
             for (; m_RedlineIndex < m_rIDRA.GetRedlineTable().size(); 
++m_RedlineIndex)
             {

Reply via email to