sw/inc/ndtxt.hxx | 1 sw/qa/extras/uiwriter/uiwriter2.cxx | 60 ++++++++++++++++++++++++++++++++++++ sw/source/core/docnode/nodes.cxx | 9 ----- sw/source/core/txtnode/ndtxt.cxx | 48 +++++++++++++++++++++------- 4 files changed, 96 insertions(+), 22 deletions(-)
New commits: commit f5cce1b4ecae6fc1e8a24b2594b0578c487be011 Author: Michael Stahl <michael.st...@cib.de> AuthorDate: Mon Oct 22 16:37:08 2018 +0200 Commit: Michael Stahl <michael.st...@cib.de> CommitDate: Mon Oct 22 16:38:01 2018 +0200 sw_redlinehide_3: adapt number tree updates in SetAttr/ResetAttr Update both of the SwNodeNums. Change-Id: Iba8aa6cda460099f4a1086d6aaa08ac98c78f097 diff --git a/sw/inc/ndtxt.hxx b/sw/inc/ndtxt.hxx index 97450d63a7a6..05bdb53b2f1f 100644 --- a/sw/inc/ndtxt.hxx +++ b/sw/inc/ndtxt.hxx @@ -424,6 +424,7 @@ public: SwNumRule *GetNumRule(bool bInParent = true) const; const SwNodeNum* GetNum(SwRootFrame const* pLayout = nullptr) const; + void DoNum(std::function<void (SwNodeNum &)> const&); SwNumberTree::tNumberVector GetNumberVector(SwRootFrame const* pLayout = nullptr) const; diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx index 215a0c79783b..4caf635d7d33 100644 --- a/sw/source/core/txtnode/ndtxt.cxx +++ b/sw/source/core/txtnode/ndtxt.cxx @@ -3974,6 +3974,21 @@ const SwNodeNum* SwTextNode::GetNum(SwRootFrame const*const pLayout) const return pLayout && pLayout->IsHideRedlines() ? mpNodeNumRLHidden : mpNodeNum; } +void SwTextNode::DoNum(std::function<void (SwNodeNum &)> const& rFunc) +{ + // temp. clear because GetActualListLevel() may be called and the assert + // there triggered during update, which is unhelpful + SwNodeNum * pBackup(mpNodeNumRLHidden); + mpNodeNumRLHidden = nullptr; + assert(mpNodeNum); + rFunc(*mpNodeNum); + if (pBackup) + { + mpNodeNumRLHidden = pBackup; + rFunc(*mpNodeNumRLHidden); + } +} + SwNumberTree::tNumberVector SwTextNode::GetNumberVector(SwRootFrame const*const pLayout) const { @@ -4837,20 +4852,24 @@ namespace { { if ( mbUpdateListLevel && mrTextNode.IsInList() ) { - const_cast<SwNodeNum*>(mrTextNode.GetNum())->SetLevelInListTree( - mrTextNode.GetAttrListLevel() ); + auto const nLevel(mrTextNode.GetAttrListLevel()); + mrTextNode.DoNum( + [nLevel](SwNodeNum & rNum) { rNum.SetLevelInListTree(nLevel); }); } if ( mbUpdateListRestart && mrTextNode.IsInList() ) { - SwNodeNum* pNodeNum = const_cast<SwNodeNum*>(mrTextNode.GetNum()); - pNodeNum->InvalidateMe(); - pNodeNum->NotifyInvalidSiblings(); + mrTextNode.DoNum( + [](SwNodeNum & rNum) { + rNum.InvalidateMe(); + rNum.NotifyInvalidSiblings(); + }); } if ( mbUpdateListCount && mrTextNode.IsInList() ) { - const_cast<SwNodeNum*>(mrTextNode.GetNum())->InvalidateAndNotifyTree(); + mrTextNode.DoNum( + [](SwNodeNum & rNum) { rNum.InvalidateAndNotifyTree(); }); } } @@ -5156,21 +5175,24 @@ namespace { { if ( mbUpdateListLevel ) { - SwNodeNum* pNodeNum = const_cast<SwNodeNum*>(mrTextNode.GetNum()); - pNodeNum->SetLevelInListTree( mrTextNode.GetAttrListLevel() ); + auto const nLevel(mrTextNode.GetAttrListLevel()); + mrTextNode.DoNum( + [nLevel](SwNodeNum & rNum) { rNum.SetLevelInListTree(nLevel); }); } if ( mbUpdateListRestart ) { - SwNodeNum* pNodeNum = const_cast<SwNodeNum*>(mrTextNode.GetNum()); - pNodeNum->InvalidateMe(); - pNodeNum->NotifyInvalidSiblings(); + mrTextNode.DoNum( + [](SwNodeNum & rNum) { + rNum.InvalidateMe(); + rNum.NotifyInvalidSiblings(); + }); } if ( mbUpdateListCount ) { - SwNodeNum* pNodeNum = const_cast<SwNodeNum*>(mrTextNode.GetNum()); - pNodeNum->InvalidateAndNotifyTree(); + mrTextNode.DoNum( + [](SwNodeNum & rNum) { rNum.InvalidateAndNotifyTree(); }); } } } commit 93288d55aea7b82b2aa75c5d11dd9a51b55a1a46 Author: Michael Stahl <michael.st...@cib.de> AuthorDate: Mon Oct 22 11:53:10 2018 +0200 Commit: Michael Stahl <michael.st...@cib.de> CommitDate: Mon Oct 22 14:34:11 2018 +0200 sw_redlinehide_3: remove dubious fallback code from SwNodes::ChgNode() There is no obvious case where such a fallback would be needed, but it does introduce a bug with a delete redline inside a hidden section: on Show, when moving the nodes into the body content, FindPrvNxtFrameNode() will return nullptr because there are no frames inside the hidden section, but then this fallback will cause it to erroneously create a frame. Change-Id: I2328a6f213fdec95857b6e4446e1a8504c17f599 diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx index 205d46b98fe0..84bab77ad0e1 100644 --- a/sw/qa/extras/uiwriter/uiwriter2.cxx +++ b/sw/qa/extras/uiwriter/uiwriter2.cxx @@ -24,6 +24,7 @@ class SwUiWriterTest2 : public SwModelTestBase { public: void testRedlineMoveInsertInDelete(); + void testRedlineInHiddenSection(); void testTdf101534(); void testTdf54819(); void testTdf119571(); @@ -31,6 +32,7 @@ public: CPPUNIT_TEST_SUITE(SwUiWriterTest2); CPPUNIT_TEST(testRedlineMoveInsertInDelete); + CPPUNIT_TEST(testRedlineInHiddenSection); CPPUNIT_TEST(testTdf101534); CPPUNIT_TEST(testTdf54819); CPPUNIT_TEST(testTdf119571); @@ -74,6 +76,64 @@ void SwUiWriterTest2::testRedlineMoveInsertInDelete() pWrtShell->GetCursor()->GetPoint()->nNode.GetNode().GetTextNode()->GetText()); } +void SwUiWriterTest2::testRedlineInHiddenSection() +{ + loadURL("private:factory/swriter", nullptr); + SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + SwWrtShell* const pWrtShell = pTextDoc->GetDocShell()->GetWrtShell(); + + pWrtShell->SplitNode(); + pWrtShell->Insert("foo"); + pWrtShell->SplitNode(); + pWrtShell->Insert("bar"); + pWrtShell->SplitNode(); + pWrtShell->Insert("baz"); + + RedlineFlags const mode(pWrtShell->GetRedlineFlags() | RedlineFlags::On); + CPPUNIT_ASSERT(mode & (RedlineFlags::ShowDelete | RedlineFlags::ShowInsert)); + pWrtShell->SetRedlineFlags(mode); + + // delete paragraph "bar" + pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/false, 2, /*bBasicCall=*/false); + pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/true, 8, /*bBasicCall=*/false); + pWrtShell->Delete(); + + pWrtShell->StartOfSection(); + pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, /*bBasicCall=*/false); + pWrtShell->EndOfSection(true); + + SwSectionData section(CONTENT_SECTION, pWrtShell->GetUniqueSectionName()); + section.SetHidden(true); + SwSection const* pSection = pWrtShell->InsertSection(section, nullptr); + + SwSectionNode const* pNode = pSection->GetFormat()->GetSectionNode(); + + CPPUNIT_ASSERT( + !pNode->GetNodes()[pNode->GetIndex() + 1]->GetTextNode()->getLayoutFrame(nullptr)); + CPPUNIT_ASSERT( + !pNode->GetNodes()[pNode->GetIndex() + 2]->GetTextNode()->getLayoutFrame(nullptr)); + CPPUNIT_ASSERT( + !pNode->GetNodes()[pNode->GetIndex() + 3]->GetTextNode()->getLayoutFrame(nullptr)); + CPPUNIT_ASSERT(pNode->GetNodes()[pNode->GetIndex() + 4]->IsEndNode()); + + pWrtShell->SetRedlineFlags(mode & ~RedlineFlags::ShowDelete); // hide + + CPPUNIT_ASSERT( + !pNode->GetNodes()[pNode->GetIndex() + 1]->GetTextNode()->getLayoutFrame(nullptr)); + CPPUNIT_ASSERT(pNode->GetNodes()[pNode->GetIndex() + 2]->IsEndNode()); + + pWrtShell->SetRedlineFlags(mode); // show again + + CPPUNIT_ASSERT( + !pNode->GetNodes()[pNode->GetIndex() + 1]->GetTextNode()->getLayoutFrame(nullptr)); + // there was a frame created here + CPPUNIT_ASSERT( + !pNode->GetNodes()[pNode->GetIndex() + 2]->GetTextNode()->getLayoutFrame(nullptr)); + CPPUNIT_ASSERT( + !pNode->GetNodes()[pNode->GetIndex() + 3]->GetTextNode()->getLayoutFrame(nullptr)); + CPPUNIT_ASSERT(pNode->GetNodes()[pNode->GetIndex() + 4]->IsEndNode()); +} + void SwUiWriterTest2::testTdf101534() { // Copy the first paragraph of the document. diff --git a/sw/source/core/docnode/nodes.cxx b/sw/source/core/docnode/nodes.cxx index 8319df67ed10..324814567e2c 100644 --- a/sw/source/core/docnode/nodes.cxx +++ b/sw/source/core/docnode/nodes.cxx @@ -358,15 +358,6 @@ void SwNodes::ChgNode( SwNodeIndex const & rDelPos, sal_uLong nSz, SwNode* pFrameNd = rNds.FindPrvNxtFrameNode( aFrameNdIdx, rNds[ rInsPos.GetIndex() - 1 ] ); - if( !pFrameNd && aFrameNdIdx > rNds.GetEndOfExtras().GetIndex() ) - { - OSL_ENSURE( false, "here, something wrong happened" ); - aFrameNdIdx = rNds.GetEndOfContent(); - pFrameNd = SwNodes::GoPrevSection( &aFrameNdIdx, true, false ); - if( pFrameNd && !static_cast<SwContentNode*>(pFrameNd)->HasWriterListeners() ) - pFrameNd = nullptr; - OSL_ENSURE( pFrameNd, "ChgNode() - no FrameNode found" ); - } if( pFrameNd ) while( aIdx != rInsPos ) { _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits