diff options
author | László Németh <nemeth@numbertext.org> | 2020-12-16 12:23:22 +0100 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2020-12-17 22:50:18 +0100 |
commit | 709f14321f3e6da69677c138d769fd8084b1c7e6 (patch) | |
tree | a4f9b8eeaf04a13e71c433a02699e67ff824c999 | |
parent | 08e8fb0cba7edbba4436096c248bab30c0564b28 (diff) |
sw ChangesInMargin: fix crash at Undo of deletion of paragraph break
Deletion of the paragraph break by pressing Delete results
an empty hidden redline, too, which caused a problem during Undo
(if there were other tracked redlines, too).
Change-Id: I64968688688be72d4e501631244b4c57ab634585
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107830
Tested-by: Jenkins
Reviewed-by: László Németh <nemeth@numbertext.org>
(cherry picked from commit 172373c4a2c4a66b8abbe26dbe07fd621c971ed0)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107899
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter2.cxx | 41 | ||||
-rw-r--r-- | sw/source/core/undo/unredln.cxx | 4 |
2 files changed, 43 insertions, 2 deletions
diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx index c3d4d71d6b5c..496b9b8602bc 100644 --- a/sw/qa/extras/uiwriter/uiwriter2.cxx +++ b/sw/qa/extras/uiwriter/uiwriter2.cxx @@ -2084,6 +2084,47 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf137771) CPPUNIT_ASSERT(!pWrtShell->GetViewOptions()->IsShowChangesInMargin()); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testJoinParaChangesInMargin) +{ + load(DATA_DIRECTORY, "tdf54819.fodt"); + + SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + + // switch on "Show changes in margin" mode + dispatchCommand(mxComponent, ".uno:ShowChangesInMargin", {}); + + SwWrtShell* const pWrtShell = pTextDoc->GetDocShell()->GetWrtShell(); + CPPUNIT_ASSERT(pWrtShell->GetViewOptions()->IsShowChangesInMargin()); + + // turn on red-lining and show changes + SwDoc* pDoc = pWrtShell->GetDoc(); + pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::On | RedlineFlags::ShowInsert + | RedlineFlags::ShowDelete); + CPPUNIT_ASSERT_MESSAGE("redlining should be on", + pDoc->getIDocumentRedlineAccess().IsRedlineOn()); + CPPUNIT_ASSERT_MESSAGE( + "redlines should be visible", + IDocumentRedlineAccess::IsShowChanges(pDoc->getIDocumentRedlineAccess().GetRedlineFlags())); + + // delete a character and the paragraph break at the end of the paragraph + dispatchCommand(mxComponent, ".uno:GotoEndOfPara", {}); + pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/true, 1, /*bBasicCall=*/false); + dispatchCommand(mxComponent, ".uno:Delete", {}); + dispatchCommand(mxComponent, ".uno:Delete", {}); + CPPUNIT_ASSERT_EQUAL(OUString("Lorem ipsudolor sit amet."), getParagraph(1)->getString()); + + // Undo + dispatchCommand(mxComponent, ".uno:Undo", {}); + // this would crash due to bad redline range + dispatchCommand(mxComponent, ".uno:Undo", {}); + CPPUNIT_ASSERT_EQUAL(OUString("Lorem ipsum"), getParagraph(1)->getString()); + + // switch off "Show changes in margin" mode + dispatchCommand(mxComponent, ".uno:ShowChangesInMargin", {}); + CPPUNIT_ASSERT(!pWrtShell->GetViewOptions()->IsShowChangesInMargin()); +} + CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf138479) { SwDoc* const pDoc = createDoc(); diff --git a/sw/source/core/undo/unredln.cxx b/sw/source/core/undo/unredln.cxx index 93d0b0d393a2..0e0d89765beb 100644 --- a/sw/source/core/undo/unredln.cxx +++ b/sw/source/core/undo/unredln.cxx @@ -107,7 +107,7 @@ void SwUndoRedline::UndoImpl(::sw::UndoRedoContext & rContext) for( SwRedlineTable::size_type n = 1; n < rTable.size(); ++n ) { SwRangeRedline *pRed(rTable[n]); - if ( pRedline->GetId() < pRed->GetId() && pRed->GetId() < nMaxId ) + if ( !pRed->HasMark() && pRedline->GetId() < pRed->GetId() && pRed->GetId() < nMaxId ) { nCurRedlinePos = n; pRedline = pRed; @@ -116,7 +116,7 @@ void SwUndoRedline::UndoImpl(::sw::UndoRedoContext & rContext) nMaxId = pRedline->GetId(); - if ( !pRedline->IsVisible() ) + if ( !pRedline->IsVisible() && !pRedline->HasMark() ) { // set it visible pRedline->Show(0, rTable.GetPos(pRedline), /*bForced=*/true); |