diff --git a/editeng/qa/unit/core-test.cxx b/editeng/qa/unit/core-test.cxx index f34240e3b1eb..6991e4c514cc 100644 --- a/editeng/qa/unit/core-test.cxx +++ b/editeng/qa/unit/core-test.cxx @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -139,6 +140,7 @@ public: void testTdf162803StaleKashidaArray(); void testTdf157037PasteTextAutoDirection(); void testFontVariationsItem(); + void testEscapementNotPreservedOnParaBreak(); DECL_STATIC_LINK(Test, CalcFieldValueHdl, EditFieldInfo*, void); @@ -175,6 +177,7 @@ public: CPPUNIT_TEST(testTdf162803StaleKashidaArray); CPPUNIT_TEST(testTdf157037PasteTextAutoDirection); CPPUNIT_TEST(testFontVariationsItem); + CPPUNIT_TEST(testEscapementNotPreservedOnParaBreak); CPPUNIT_TEST_SUITE_END(); private: @@ -2498,7 +2501,50 @@ void Test::testFontVariationsItem() SvxFontVariationsItem aItem4(EE_CHAR_FONTVARIATIONS); CPPUNIT_ASSERT(aItem4.PutValue(aAny, 0)); CPPUNIT_ASSERT(aItem4.operator==(aItem2)); +} +void Test::testEscapementNotPreservedOnParaBreak() +{ + EditEngine aEditEngine(mpItemPool.get()); + EditDoc& rDoc = aEditEngine.GetEditDoc(); + + OUString aParaText = u"item 1st"_ustr; + aEditEngine.SetText(aParaText); + CPPUNIT_ASSERT_EQUAL(aParaText, rDoc.GetParaAsString(sal_Int32(0))); + + { + std::unique_ptr pSet(new SfxItemSet(aEditEngine.GetEmptyItemSet())); + SvxEscapementItem aSuperscript(SvxEscapement::Superscript, EE_CHAR_ESCAPEMENT); + pSet->Put(aSuperscript); + aEditEngine.QuickSetAttribs(*pSet, ESelection(0, 6, 0, 8)); + } + + { + std::unique_ptr pSet(new SfxItemSet(aEditEngine.GetEmptyItemSet())); + SvxWeightItem aBold(WEIGHT_BOLD, EE_CHAR_WEIGHT); + pSet->Put(aBold); + aEditEngine.QuickSetAttribs(*pSet, ESelection(0, 6, 0, 8)); + } + + // new para break at the end of the text (cf. pressing enter) + ContentNode* pNode = rDoc.GetObject(0); + CPPUNIT_ASSERT(pNode); + EditPaM aEndPaM(pNode, pNode->Len()); + rDoc.InsertParaBreak(aEndPaM, true /* bKeepEndingAttribs */); + + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), rDoc.Count()); + CPPUNIT_ASSERT_EQUAL(aParaText, rDoc.GetParaAsString(sal_Int32(0))); + CPPUNIT_ASSERT_EQUAL(OUString(), rDoc.GetParaAsString(sal_Int32(1))); + + // Check new para's character attributes + pNode = rDoc.GetObject(1); + CPPUNIT_ASSERT(pNode); + + const EditCharAttrib* pBoldAttr = pNode->GetCharAttribs().FindEmptyAttrib(EE_CHAR_WEIGHT, 0); + CPPUNIT_ASSERT_MESSAGE("Bold attribute should be carried over.", pBoldAttr != nullptr); + + const EditCharAttrib* pEscAttr = pNode->GetCharAttribs().FindEmptyAttrib(EE_CHAR_ESCAPEMENT, 0); + CPPUNIT_ASSERT_MESSAGE("Escapement attribute should NOT be included.", !pEscAttr); } CPPUNIT_TEST_SUITE_REGISTRATION(Test); diff --git a/editeng/source/editeng/ContentNode.cxx b/editeng/source/editeng/ContentNode.cxx index 56c2659c7025..1904e55cb1aa 100644 --- a/editeng/source/editeng/ContentNode.cxx +++ b/editeng/source/editeng/ContentNode.cxx @@ -302,7 +302,8 @@ void ContentNode::CopyAndCutAttribs( ContentNode* pPrevNode, SfxItemPool& rPool, else if ( pAttrib->GetEnd() == nCut ) { // must be copied as an empty attributes. - if ( bKeepEndingAttribs && !pAttrib->IsFeature() && !maCharAttribList.FindAttrib( pAttrib->GetItem()->Which(), 0 ) ) + if ( bKeepEndingAttribs && !pAttrib->IsFeature() && !maCharAttribList.FindAttrib( pAttrib->GetItem()->Which(), 0 ) + && pAttrib->GetItem()->Which() != EE_CHAR_ESCAPEMENT ) { EditCharAttrib* pNewAttrib = MakeCharAttrib( rPool, *(pAttrib->GetItem()), 0, 0 ); assert(pNewAttrib);