From 22639148ae5400bac98f32a75d7431b857c80195 Mon Sep 17 00:00:00 2001 From: László Németh Date: Tue, 28 Aug 2018 18:23:17 +0200 Subject: tdf#54819 change tracking: keep paragraph style after full deletion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit of the previous paragraph(s), as in editing without change tracking. This is a workaround for the regression introduced by #i100466#. NOTE: We change the style of the first removed paragraph to restore normal editing function during change tracking, too. Manual fix of the spoiled paragraph does the same style changes in the previously deleted paragraphs, so this commit doesn't introduce any new oddity. Change-Id: I9565e600ec86adc95246ff899d58de79f3c3a996 Reviewed-on: https://gerrit.libreoffice.org/59820 Tested-by: Jenkins Reviewed-by: László Németh --- sw/qa/extras/uiwriter/data2/tdf54819.fodt | 9 +++++++ sw/qa/extras/uiwriter/uiwriter2.cxx | 36 +++++++++++++++++++++++++++ sw/source/core/doc/DocumentRedlineManager.cxx | 13 ++++++++++ 3 files changed, 58 insertions(+) create mode 100644 sw/qa/extras/uiwriter/data2/tdf54819.fodt diff --git a/sw/qa/extras/uiwriter/data2/tdf54819.fodt b/sw/qa/extras/uiwriter/data2/tdf54819.fodt new file mode 100644 index 000000000000..f9a8e9d0b698 --- /dev/null +++ b/sw/qa/extras/uiwriter/data2/tdf54819.fodt @@ -0,0 +1,9 @@ + + + + + Lorem ipsum + dolor sit amet. + + + diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx index 239700294b71..0a789a73b87d 100644 --- a/sw/qa/extras/uiwriter/uiwriter2.cxx +++ b/sw/qa/extras/uiwriter/uiwriter2.cxx @@ -11,6 +11,7 @@ #include #include #include +#include namespace { @@ -22,9 +23,11 @@ class SwUiWriterTest2 : public SwModelTestBase { public: void testTdf101534(); + void testTdf54819(); CPPUNIT_TEST_SUITE(SwUiWriterTest2); CPPUNIT_TEST(testTdf101534); + CPPUNIT_TEST(testTdf54819); CPPUNIT_TEST_SUITE_END(); }; @@ -55,6 +58,39 @@ void SwUiWriterTest2::testTdf101534() CPPUNIT_ASSERT(aSet.HasItem(RES_LR_SPACE)); } +void SwUiWriterTest2::testTdf54819() +{ + load(DATA_DIRECTORY, "tdf54819.fodt"); + + SwXTextDocument* pTextDoc = dynamic_cast(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + + CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"), + getProperty(getParagraph(1), "ParaStyleName")); + CPPUNIT_ASSERT_EQUAL(OUString("Standard"), + getProperty(getParagraph(2), "ParaStyleName")); + + //turn on red-lining and hide changes + SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc(); + pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::On); + CPPUNIT_ASSERT_MESSAGE("redlining should be on", + pDoc->getIDocumentRedlineAccess().IsRedlineOn()); + CPPUNIT_ASSERT_MESSAGE("redlines shouldn't be visible", + !IDocumentRedlineAccess::IsShowChanges( + pDoc->getIDocumentRedlineAccess().GetRedlineFlags())); + + // remove first paragraph with paragraph break + SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell(); + pWrtShell->EndPara(/*bSelect=*/true); + pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/true, 1, /*bBasicCall=*/false); + rtl::Reference pTransfer = new SwTransferable(*pWrtShell); + pTransfer->Cut(); + + // remaining paragraph keeps its original style + CPPUNIT_ASSERT_EQUAL(OUString("Standard"), + getProperty(getParagraph(1), "ParaStyleName")); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest2); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/doc/DocumentRedlineManager.cxx b/sw/source/core/doc/DocumentRedlineManager.cxx index a47b75629940..6838e7fc8dcd 100644 --- a/sw/source/core/doc/DocumentRedlineManager.cxx +++ b/sw/source/core/doc/DocumentRedlineManager.cxx @@ -1680,7 +1680,20 @@ DocumentRedlineManager::AppendRedline(SwRangeRedline* pNewRedl, bool const bCall pNewRedl = nullptr; } else + { + if (pStt->nContent == 0) + { + // tdf#54819 to keep the style of the paragraph + // after the fully deleted paragraphs (normal behaviour + // of editing without change tracking), we copy its style + // to the first removed paragraph. + SwTextNode* pDelNode = pStt->nNode.GetNode().GetTextNode(); + SwTextNode* pTextNode = pEnd->nNode.GetNode().GetTextNode(); + if (pDelNode != nullptr && pTextNode != nullptr && pDelNode != pTextNode) + pTextNode->CopyCollFormat( *pDelNode ); + } mpRedlineTable->Insert( pNewRedl ); + } } if( bCompress ) -- cgit v1.2.3