From 93dce15827cc8bd69a9abb5e70a5df0292719a9a Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Thu, 19 Jul 2018 15:32:59 +0200 Subject: tdf#101534 sw: fix lost indent attributes when copying into numbered paragraph Commit aa91dc0ccbe53ffcec9dbfec2265de057775d4e3 (CWS-TOOLING: integrate CWS sw32numbf01, 2009-09-08) replaced the SwDoc::ReplaceNumRule() call with SwDoc::SetNumRule(), as the later handles list ids. This required a decision if resetting of the indent attributes is needed or not, but it did not document why resetting was chosen. On the other hand, the current bugdoc shows why resetting is a bad idea: this way if you paste into a numbered paragraph which has a non-zero paragraph indent inherited from the numbering + zero indent as direct formatting, then this later is lost during paste. (cherry picked from commit 340eaa6aa15c18cc2696a4a304350810cb36565c) Change-Id: Ie5dcf6ed86c240fd61c4d5bfed886910aea3648f Reviewed-on: https://gerrit.libreoffice.org/57739 Tested-by: Jenkins Reviewed-by: Michael Stahl --- sw/CppunitTest_sw_uiwriter.mk | 1 + sw/qa/extras/uiwriter/data2/tdf101534.fodt | 28 ++++++++++ sw/qa/extras/uiwriter/uiwriter2.cxx | 60 ++++++++++++++++++++++ .../core/doc/DocumentContentOperationsManager.cxx | 4 +- 4 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 sw/qa/extras/uiwriter/data2/tdf101534.fodt create mode 100644 sw/qa/extras/uiwriter/uiwriter2.cxx diff --git a/sw/CppunitTest_sw_uiwriter.mk b/sw/CppunitTest_sw_uiwriter.mk index 05ce1b5c90d8..68d0056172ac 100644 --- a/sw/CppunitTest_sw_uiwriter.mk +++ b/sw/CppunitTest_sw_uiwriter.mk @@ -13,6 +13,7 @@ $(eval $(call gb_CppunitTest_CppunitTest,sw_uiwriter)) $(eval $(call gb_CppunitTest_add_exception_objects,sw_uiwriter, \ sw/qa/extras/uiwriter/uiwriter \ + sw/qa/extras/uiwriter/uiwriter2 \ )) # note: this links msword only for the reason to have a order dependency, diff --git a/sw/qa/extras/uiwriter/data2/tdf101534.fodt b/sw/qa/extras/uiwriter/data2/tdf101534.fodt new file mode 100644 index 000000000000..e1db2f08ee08 --- /dev/null +++ b/sw/qa/extras/uiwriter/data2/tdf101534.fodt @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + Lorem ipsum dolor sit amet. + + + Quo dolor dolore ea, vis te dicunt evertitur. Quo idque nostrud referrentur at, saperet volumus sententiae ut pro. + + + + + diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx new file mode 100644 index 000000000000..239700294b71 --- /dev/null +++ b/sw/qa/extras/uiwriter/uiwriter2.cxx @@ -0,0 +1,60 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include + +namespace +{ +char const DATA_DIRECTORY[] = "/sw/qa/extras/uiwriter/data2/"; +} + +/// Second set of tests asserting the behavior of Writer user interface shells. +class SwUiWriterTest2 : public SwModelTestBase +{ +public: + void testTdf101534(); + + CPPUNIT_TEST_SUITE(SwUiWriterTest2); + CPPUNIT_TEST(testTdf101534); + CPPUNIT_TEST_SUITE_END(); +}; + +void SwUiWriterTest2::testTdf101534() +{ + // Copy the first paragraph of the document. + load(DATA_DIRECTORY, "tdf101534.fodt"); + SwXTextDocument* pTextDoc = dynamic_cast(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell(); + pWrtShell->EndPara(/*bSelect=*/true); + rtl::Reference pTransfer = new SwTransferable(*pWrtShell); + pTransfer->Copy(); + + // Go to the second paragraph, assert that we have margins as direct + // formatting. + pWrtShell->Down(/*bSelect=*/false); + SfxItemSet aSet(pWrtShell->GetAttrPool(), svl::Items{}); + pWrtShell->GetCurAttr(aSet); + CPPUNIT_ASSERT(aSet.HasItem(RES_LR_SPACE)); + + // Make sure that direct formatting is preserved during paste. + pWrtShell->EndPara(/*bSelect=*/false); + TransferableDataHelper aHelper(pTransfer.get()); + SwTransferable::Paste(*pWrtShell, aHelper); + pWrtShell->GetCurAttr(aSet); + // This failed, direct formatting was lost. + CPPUNIT_ASSERT(aSet.HasItem(RES_LR_SPACE)); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest2); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx b/sw/source/core/doc/DocumentContentOperationsManager.cxx index 6cee3d7973e3..256fce7bbe4d 100644 --- a/sw/source/core/doc/DocumentContentOperationsManager.cxx +++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx @@ -4580,8 +4580,10 @@ bool DocumentContentOperationsManager::CopyImpl( SwPaM& rPam, SwPosition& rPos, if ( pNumRuleToPropagate != nullptr ) { // #i86492# - use , because it also handles the + // Don't reset indent attributes, that would mean loss of direct + // formatting. pDoc->SetNumRule( *pCopyPam, *pNumRuleToPropagate, false, - aListIdToPropagate, true, true ); + aListIdToPropagate, true, /*bResetIndentAttrs=*/false ); } pDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld ); -- cgit v1.2.3