diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2018-08-05 14:23:44 +0300 |
---|---|---|
committer | Michael Stahl <Michael.Stahl@cib.de> | 2018-08-07 18:46:40 +0200 |
commit | 3c20597ada7f74a4a96dec841264593fdbf0bcd5 (patch) | |
tree | 0da26eebbe63aec64b9246191a6dfe8d5b86d786 /sw/source/core | |
parent | 1835e0c82fca788aef823d91bda4fedef26cd712 (diff) |
tdf#118859: Avoid trying to remove already removed nodes
Regression from commit db04be037b611e296ef9f2542322c52ed82d7a2b
Change-Id: I530c00f6357b4822654add6e5f2eecb3252b88ae
Reviewed-on: https://gerrit.libreoffice.org/58612
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
(cherry picked from commit 576fac6f6199a87fb07e4a067abaa18c89b6d7ea)
Reviewed-on: https://gerrit.libreoffice.org/58619
Reviewed-by: Michael Stahl <Michael.Stahl@cib.de>
Diffstat (limited to 'sw/source/core')
-rw-r--r-- | sw/source/core/doc/doc.cxx | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx index 43eee2ebad05..32b522e69767 100644 --- a/sw/source/core/doc/doc.cxx +++ b/sw/source/core/doc/doc.cxx @@ -125,6 +125,7 @@ #include <vector> #include <map> +#include <set> #include <osl/diagnose.h> #include <osl/interlck.h> #include <vbahelper/vbaaccesshelper.hxx> @@ -1342,9 +1343,8 @@ void RemoveOrDeleteContents(SwTextNode* pTextNd, IDocumentContentOperations& xOp xOperations.DelFullPara(aPam); } } -// Returns if the data was actually modified -bool HandleHidingField(SwFormatField& rFormatField, const SwNodes& rNodes, - IDocumentContentOperations& xOperations) +// Returns the node pointer which needs to hide, or nullptr if this field does not hide a node +SwTextNode* HandleHidingField(SwFormatField& rFormatField, const SwNodes& rNodes) { SwTextNode* pTextNd; if (rFormatField.GetTextField() @@ -1352,10 +1352,9 @@ bool HandleHidingField(SwFormatField& rFormatField, const SwNodes& rNodes, && pTextNd->GetpSwpHints() && pTextNd->IsHiddenByParaField() && &pTextNd->GetNodes() == &rNodes) { - RemoveOrDeleteContents(pTextNd, xOperations); - return true; + return pTextNd; } - return false; + return nullptr; } } @@ -1387,6 +1386,7 @@ bool SwDoc::FieldHidesPara(const SwField& rField) const } /// Remove the invisible content from the document e.g. hidden areas, hidden paragraphs +// Returns if the data was actually modified bool SwDoc::RemoveInvisibleContent() { bool bRet = false; @@ -1394,21 +1394,23 @@ bool SwDoc::RemoveInvisibleContent() { // Removing some nodes for one SwFieldIds::Database type might remove the type from - // document's field types, invalidating iterators. So, we need to create own list of - // matching types prior to processing them. - std::vector<const SwFieldType*> aHidingFieldTypes; + // document's field types, or try to remove already removed nodes, invalidating iterators. + // So, we need to create own list of nodes prior to removing them. + std::set<SwTextNode*> aHiddenNodes; for (const auto* pType : *getIDocumentFieldsAccess().GetFieldTypes()) { if (FieldCanHidePara(pType->Which())) - aHidingFieldTypes.push_back(pType); + { + SwIterator<SwFormatField, SwFieldType> aIter(*pType); + for (auto* pField = aIter.First(); pField; pField = aIter.Next()) + if (SwTextNode* pHiddenNode = HandleHidingField(*pField, GetNodes())) + aHiddenNodes.insert(pHiddenNode); + } } - for (const auto* pType : aHidingFieldTypes) + for (SwTextNode* pHiddenNode : aHiddenNodes) { - SwIterator<SwFormatField, SwFieldType> aIter(*pType); - for (SwFormatField* pFormatField = aIter.First(); pFormatField; - pFormatField = aIter.Next()) - bRet |= HandleHidingField(*pFormatField, GetNodes(), - getIDocumentContentOperations()); + bRet = true; + RemoveOrDeleteContents(pHiddenNode, getIDocumentContentOperations()); } } |