diff options
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter2.cxx | 83 | ||||
-rw-r--r-- | sw/source/core/edit/autofmt.cxx | 25 |
2 files changed, 100 insertions, 8 deletions
diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx index 25015b50e3c5..f2969c14402f 100644 --- a/sw/qa/extras/uiwriter/uiwriter2.cxx +++ b/sw/qa/extras/uiwriter/uiwriter2.cxx @@ -46,6 +46,9 @@ #include <sfx2/dispatch.hxx> #include <svl/stritem.hxx> #include <comphelper/lok.hxx> +#include <comphelper/scopeguard.hxx> +#include <editeng/acorrcfg.hxx> +#include <swacorr.hxx> #include <txtfrm.hxx> #include <redline.hxx> #include <view.hxx> @@ -347,6 +350,86 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testRedlineSplitContentNode) rUndoManager.Undo(); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf137245) +{ + SwDoc* const pDoc(createDoc()); + SwWrtShell* const pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + SwAutoCorrect corr(*SvxAutoCorrCfg::Get().GetAutoCorrect()); + corr.GetSwFlags().bSetBorder = true; + // sigh, it's a global... err i mean Singleton design pattern *eyeroll* + SvxSwAutoFormatFlags flags(*SwEditShell::GetAutoFormatFlags()); + comphelper::ScopeGuard const g([=]() { SwEditShell::SetAutoFormatFlags(&flags); }); + flags.bSetBorder = true; + SwEditShell::SetAutoFormatFlags(&flags); + + { + SwFormatAnchor anchor(RndStdIds::FLY_AT_PARA); + anchor.SetAnchor(pWrtShell->GetCursor()->GetPoint()); + SfxItemSet flySet(pDoc->GetAttrPool(), + svl::Items<RES_FRM_SIZE, RES_FRM_SIZE, RES_ANCHOR, RES_ANCHOR>{}); + flySet.Put(anchor); + SwFormatFrameSize size(SwFrameSize::Minimum, 1000, 1000); + flySet.Put(size); // set a size, else we get 1 char per line... + SwFrameFormat const* pFly = pWrtShell->NewFlyFrame(flySet, /*bAnchValid=*/true); + CPPUNIT_ASSERT(pFly != nullptr); + } + { + SwFormatAnchor anchor(RndStdIds::FLY_AT_CHAR); + anchor.SetAnchor(pWrtShell->GetCursor()->GetPoint()); + SfxItemSet flySet(pDoc->GetAttrPool(), + svl::Items<RES_FRM_SIZE, RES_FRM_SIZE, RES_ANCHOR, RES_ANCHOR>{}); + flySet.Put(anchor); + SwFormatFrameSize size(SwFrameSize::Minimum, 1000, 1000); + flySet.Put(size); // set a size, else we get 1 char per line... + SwFrameFormat const* pFly = pWrtShell->NewFlyFrame(flySet, /*bAnchValid=*/true); + CPPUNIT_ASSERT(pFly != nullptr); + } + // move cursor back to body + pWrtShell->SttEndDoc(false); + // keep first paragraph empty so that its flys may be deleted too + //pWrtShell->Insert("abc"); + pWrtShell->SplitNode(false); + + { + SwFormatAnchor anchor(RndStdIds::FLY_AT_PARA); + anchor.SetAnchor(pWrtShell->GetCursor()->GetPoint()); + SfxItemSet flySet(pDoc->GetAttrPool(), + svl::Items<RES_FRM_SIZE, RES_FRM_SIZE, RES_ANCHOR, RES_ANCHOR>{}); + flySet.Put(anchor); + SwFormatFrameSize size(SwFrameSize::Minimum, 1000, 1000); + flySet.Put(size); // set a size, else we get 1 char per line... + SwFrameFormat const* pFly = pWrtShell->NewFlyFrame(flySet, /*bAnchValid=*/true); + CPPUNIT_ASSERT(pFly != nullptr); + } + { + SwFormatAnchor anchor(RndStdIds::FLY_AT_CHAR); + anchor.SetAnchor(pWrtShell->GetCursor()->GetPoint()); + SfxItemSet flySet(pDoc->GetAttrPool(), + svl::Items<RES_FRM_SIZE, RES_FRM_SIZE, RES_ANCHOR, RES_ANCHOR>{}); + flySet.Put(anchor); + SwFormatFrameSize size(SwFrameSize::Minimum, 1000, 1000); + flySet.Put(size); // set a size, else we get 1 char per line... + SwFrameFormat const* pFly = pWrtShell->NewFlyFrame(flySet, /*bAnchValid=*/true); + CPPUNIT_ASSERT(pFly != nullptr); + } + + const SwFrameFormats& rFormats = *pDoc->GetSpzFrameFormats(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), rFormats.size()); + + // move cursor back to body + pWrtShell->SttEndDoc(false); + pWrtShell->Insert("---"); + pWrtShell->SplitNode(true); + + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), rFormats.size()); + + // check that the AutoFormat did something + pWrtShell->SttEndDoc(true); + SfxItemSet set{ pDoc->GetAttrPool(), svl::Items<RES_BOX, RES_BOX>{} }; + pWrtShell->GetCurParAttr(set); + CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, set.GetItemState(RES_BOX, false)); +} + CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf132236) { load(DATA_DIRECTORY, "tdf132236.odt"); diff --git a/sw/source/core/edit/autofmt.cxx b/sw/source/core/edit/autofmt.cxx index 696d26a2d901..f373c85963ba 100644 --- a/sw/source/core/edit/autofmt.cxx +++ b/sw/source/core/edit/autofmt.cxx @@ -1248,7 +1248,7 @@ void SwAutoFormat::DelEmptyLine( bool bTstNextPara ) // delete blanks in empty paragraph m_aDelPam.DeleteMark(); *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos( - TextFrameIndex(m_pCurTextFrame->GetText().getLength())); + TextFrameIndex(0)); m_aDelPam.SetMark(); m_aDelPam.GetMark()->nNode = m_pCurTextFrame->GetTextNodeFirst()->GetIndex() - 1; @@ -1267,16 +1267,25 @@ void SwAutoFormat::DelEmptyLine( bool bTstNextPara ) if( pTNd ) { m_aDelPam.GetMark()->nContent.Assign( pTNd, 0 ); - *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(TextFrameIndex(0)); + *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos( + TextFrameIndex(m_pCurTextFrame->GetText().getLength())); } } - else - { - *m_aDelPam.GetMark() = m_pCurTextFrame->MapViewToModelPos(TextFrameIndex(0)); - pTNd = m_pCurTextNd; - } if( pTNd ) - DeleteSel( m_aDelPam ); + { // join with previous or next paragraph + DeleteSel(m_aDelPam); + } + assert(m_aDelPam.GetNode().IsTextNode()); + assert(!m_aDelPam.HasMark()); + m_aDelPam.SetMark(); // mark remains at join position + m_pCurTextFrame = GetFrame(*m_aDelPam.GetNode().GetTextNode()); + // replace until the end of the merged paragraph + *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos( + TextFrameIndex(m_pCurTextFrame->GetText().getLength())); + if (*m_aDelPam.GetPoint() != *m_aDelPam.GetMark()) + { // tdf#137245 replace (not delete) to preserve any flys + m_pDoc->getIDocumentContentOperations().ReplaceRange(m_aDelPam, "", false); + } m_aDelPam.DeleteMark(); ClearRedlineText(); |