Kaydet (Commit) 576fac6f authored tarafından Mike Kaganski's avatar Mike Kaganski

tdf#118859: Avoid trying to remove already removed nodes

Regression from commit db04be03

Change-Id: I530c00f6357b4822654add6e5f2eecb3252b88ae
Reviewed-on: https://gerrit.libreoffice.org/58612
Tested-by: Jenkins
Reviewed-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
üst 74edd968
...@@ -124,6 +124,7 @@ ...@@ -124,6 +124,7 @@
#include <vector> #include <vector>
#include <map> #include <map>
#include <set>
#include <osl/diagnose.h> #include <osl/diagnose.h>
#include <osl/interlck.h> #include <osl/interlck.h>
#include <vbahelper/vbaaccesshelper.hxx> #include <vbahelper/vbaaccesshelper.hxx>
...@@ -1341,9 +1342,8 @@ void RemoveOrDeleteContents(SwTextNode* pTextNd, IDocumentContentOperations& xOp ...@@ -1341,9 +1342,8 @@ void RemoveOrDeleteContents(SwTextNode* pTextNd, IDocumentContentOperations& xOp
xOperations.DelFullPara(aPam); xOperations.DelFullPara(aPam);
} }
} }
// Returns if the data was actually modified // Returns the node pointer which needs to hide, or nullptr if this field does not hide a node
bool HandleHidingField(SwFormatField& rFormatField, const SwNodes& rNodes, SwTextNode* HandleHidingField(SwFormatField& rFormatField, const SwNodes& rNodes)
IDocumentContentOperations& xOperations)
{ {
SwTextNode* pTextNd; SwTextNode* pTextNd;
if (rFormatField.GetTextField() if (rFormatField.GetTextField()
...@@ -1351,10 +1351,9 @@ bool HandleHidingField(SwFormatField& rFormatField, const SwNodes& rNodes, ...@@ -1351,10 +1351,9 @@ bool HandleHidingField(SwFormatField& rFormatField, const SwNodes& rNodes,
&& pTextNd->GetpSwpHints() && pTextNd->IsHiddenByParaField() && pTextNd->GetpSwpHints() && pTextNd->IsHiddenByParaField()
&& &pTextNd->GetNodes() == &rNodes) && &pTextNd->GetNodes() == &rNodes)
{ {
RemoveOrDeleteContents(pTextNd, xOperations); return pTextNd;
return true;
} }
return false; return nullptr;
} }
} }
...@@ -1386,6 +1385,7 @@ bool SwDoc::FieldHidesPara(const SwField& rField) const ...@@ -1386,6 +1385,7 @@ bool SwDoc::FieldHidesPara(const SwField& rField) const
} }
/// Remove the invisible content from the document e.g. hidden areas, hidden paragraphs /// Remove the invisible content from the document e.g. hidden areas, hidden paragraphs
// Returns if the data was actually modified
bool SwDoc::RemoveInvisibleContent() bool SwDoc::RemoveInvisibleContent()
{ {
bool bRet = false; bool bRet = false;
...@@ -1393,21 +1393,23 @@ bool SwDoc::RemoveInvisibleContent() ...@@ -1393,21 +1393,23 @@ bool SwDoc::RemoveInvisibleContent()
{ {
// Removing some nodes for one SwFieldIds::Database type might remove the type from // 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 // document's field types, or try to remove already removed nodes, invalidating iterators.
// matching types prior to processing them. // So, we need to create own list of nodes prior to removing them.
std::vector<const SwFieldType*> aHidingFieldTypes; std::set<SwTextNode*> aHiddenNodes;
for (const auto* pType : *getIDocumentFieldsAccess().GetFieldTypes()) for (const auto* pType : *getIDocumentFieldsAccess().GetFieldTypes())
{ {
if (FieldCanHidePara(pType->Which())) 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); bRet = true;
for (SwFormatField* pFormatField = aIter.First(); pFormatField; RemoveOrDeleteContents(pHiddenNode, getIDocumentContentOperations());
pFormatField = aIter.Next())
bRet |= HandleHidingField(*pFormatField, GetNodes(),
getIDocumentContentOperations());
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment