sw/qa/extras/uiwriter/uiwriter2.cxx |   38 ++++++++++++++++++++++++++++++++++++
 sw/source/core/txtnode/ndtxt.cxx    |    4 +--
 2 files changed, 40 insertions(+), 2 deletions(-)

New commits:
commit c1c61f4acad1ef3881a2524db35d4e8741aeb874
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Fri Mar 4 19:18:27 2022 +0100
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Tue Mar 8 10:52:25 2022 +0100

    tdf#140077 sw_redlinehide: fix crash on SplitNode()
    
    The problem is that CutImpl() was called with nLen=0 and so returned
    without sending any hint to SwTextFrame.
    
    Then the MergedPara gets recreated, but the problem is that the
    SwParaPortion is never invalidated so it still contains the portions of
    the previous merged paragraph, and painting it will crash.
    
    But it turns out that there isn't a hint that would actually work here;
    instead, generalise a condition in SwTextNode::SplitContentNode()
    to simply throw away the portions.
    
    (regression from commit eb92dc08f2abf5ed088da0d736266f213adf00de)
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131039
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    (cherry picked from commit 6518c45dc0c2fb67500af85b97ed40466fd1d1e0)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131026
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>
    (cherry picked from commit c85863a3b4c632cdf6b6a7448fcf49ffb6bb5f11)
    
    Change-Id: I06091ca695ea9180b32e61ddb88ce64fbf20443e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131113
    Tested-by: Michael Stahl <michael.st...@allotropia.de>
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx 
b/sw/qa/extras/uiwriter/uiwriter2.cxx
index f19980387677..82b19fa95c71 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -1170,6 +1170,44 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, 
testTdf119571_keep_numbering_with_Reject)
     CPPUNIT_ASSERT_MESSAGE("Bad numbering", sNumName.isEmpty());
 }
 
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf140077)
+{
+    SwDoc* const pDoc = createDoc();
+
+    SwWrtShell* const pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+
+    // hide
+    lcl_dispatchCommand(mxComponent, ".uno:ShowTrackedChanges", {});
+
+    pWrtShell->Insert("a");
+    pWrtShell->SplitNode();
+    pWrtShell->Insert("b");
+    pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, 
/*bBasicCall=*/false);
+    pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/true, 1, 
/*bBasicCall=*/false);
+    // enable
+    lcl_dispatchCommand(mxComponent, ".uno:TrackChanges", {});
+
+    CPPUNIT_ASSERT_MESSAGE("redlining should be on",
+                           pDoc->getIDocumentRedlineAccess().IsRedlineOn());
+    CPPUNIT_ASSERT_MESSAGE(
+        "redlines should be visible",
+        
IDocumentRedlineAccess::IsShowChanges(pDoc->getIDocumentRedlineAccess().GetRedlineFlags()));
+    CPPUNIT_ASSERT(pWrtShell->GetLayout()->IsHideRedlines());
+
+    pWrtShell->Delete();
+    pWrtShell->SttEndDoc(/*bStart=*/false);
+    pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, 
/*bBasicCall=*/false);
+    lcl_dispatchCommand(mxComponent, ".uno:TrackChanges", {});
+
+    // crashed in layout
+    pWrtShell->SplitNode();
+
+    pWrtShell->Undo();
+    pWrtShell->Redo();
+    pWrtShell->Undo();
+    pWrtShell->Redo();
+}
+
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf109376_redline)
 {
     SwDoc* pDoc = createDoc();
diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
index 4bac0f11fe93..1660f5ae5f7c 100644
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -666,9 +666,9 @@ SwTextNode *SwTextNode::SplitContentNode(const SwPosition & 
rPos,
                 // Update the extents with new node; also inits merge flag,
                 // so the MakeFramesForAdjacentContentNode below respects it
                 pFrame->RegisterToNode(*pNode);
-                if (pFrame->GetText().isEmpty())
+                if (nSplitPos == 0)
                 {
-                    // turns out it's empty - in this case, it was not
+                    // in this case, it was not
                     // invalidated because Cut didn't sent it any hints,
                     // so we have to invalidate it here!
                     pFrame->Prepare(PREP_CLEAR, nullptr, false);

Reply via email to