summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sw/CppunitTest_sw_core_txtnode.mk1
-rw-r--r--sw/qa/core/txtnode/txtnode.cxx25
-rw-r--r--sw/source/core/txtnode/ndtxt.cxx31
3 files changed, 57 insertions, 0 deletions
diff --git a/sw/CppunitTest_sw_core_txtnode.mk b/sw/CppunitTest_sw_core_txtnode.mk
index 54aa0865cce3..441e415267b7 100644
--- a/sw/CppunitTest_sw_core_txtnode.mk
+++ b/sw/CppunitTest_sw_core_txtnode.mk
@@ -21,6 +21,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sw_core_txtnode, \
comphelper \
cppu \
cppuhelper \
+ editeng \
sal \
sfx \
svxcore \
diff --git a/sw/qa/core/txtnode/txtnode.cxx b/sw/qa/core/txtnode/txtnode.cxx
index 72763909122f..ed8759112ae1 100644
--- a/sw/qa/core/txtnode/txtnode.cxx
+++ b/sw/qa/core/txtnode/txtnode.cxx
@@ -16,6 +16,7 @@
#include <vcl/scheduler.hxx>
#include <sfx2/lokhelper.hxx>
#include <test/lokcallback.hxx>
+#include <editeng/escapementitem.hxx>
#include <IDocumentStatistics.hxx>
#include <fmtanchr.hxx>
@@ -183,6 +184,30 @@ CPPUNIT_TEST_FIXTURE(SwCoreTxtnodeTest, testFlyAnchorUndo)
CPPUNIT_ASSERT_EQUAL(nExpected, nActual);
}
+CPPUNIT_TEST_FIXTURE(SwCoreTxtnodeTest, testSplitNodeSuperscriptCopy)
+{
+ // Given a document with superscript text at the end of a paragraph:
+ SwDoc* pDoc = createSwDoc();
+ SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+ pWrtShell->Insert("1st");
+ pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/true, 2, /*bBasicCall=*/false);
+ SfxItemSetFixed<RES_CHRATR_ESCAPEMENT, RES_CHRATR_ESCAPEMENT> aSet(pWrtShell->GetAttrPool());
+ SvxEscapementItem aItem(SvxEscapement::Superscript, RES_CHRATR_ESCAPEMENT);
+ aSet.Put(aItem);
+ pWrtShell->SetAttrSet(aSet);
+
+ // When hitting enter at the end of the paragraph:
+ pWrtShell->SttEndDoc(/*bStt=*/false);
+ pWrtShell->SplitNode(/*bAutoFormat=*/true);
+
+ // Then make sure that the superscript formatting doesn't appear on the next paragraph:
+ aSet.ClearItem(RES_CHRATR_ESCAPEMENT);
+ pWrtShell->GetCurAttr(aSet);
+ // Without the accompanying fix in place, this test would have failed, the unexpected
+ // superscript appeared in the next paragraph.
+ CPPUNIT_ASSERT(!aSet.HasItem(RES_CHRATR_ESCAPEMENT));
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
index 591a75431cc9..d9905fce33cc 100644
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -698,6 +698,37 @@ SwTextNode *SwTextNode::SplitContentNode(const SwPosition & rPos,
}
}
+ // pNode is the previous node, 'this' is the next node from the split.
+ if (nSplitPos == nTextLen && m_pSwpHints)
+ {
+ // We just created an empty next node: avoid unwanted superscript in the new node if it's
+ // there.
+ for (size_t i = 0; i < m_pSwpHints->Count(); ++i)
+ {
+ SwTextAttr* pHt = m_pSwpHints->Get(i);
+ if (pHt->Which() != RES_TXTATR_AUTOFMT)
+ {
+ continue;
+ }
+
+ const sal_Int32* pEnd = pHt->GetEnd();
+ if (!pEnd || pHt->GetStart() != *pEnd)
+ {
+ continue;
+ }
+
+ const std::shared_ptr<SfxItemSet>& pSet = pHt->GetAutoFormat().GetStyleHandle();
+ if (!pSet || pSet->Count() != 1 || !pSet->GetItem(RES_CHRATR_ESCAPEMENT))
+ {
+ continue;
+ }
+
+ m_pSwpHints->DeleteAtPos(i);
+ SwTextAttr::Destroy(pHt, GetDoc().GetAttrPool());
+ --i;
+ }
+ }
+
#ifndef NDEBUG
if (isHide) // otherwise flags won't be set anyway
{