summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
Diffstat (limited to 'sc')
-rw-r--r--sc/source/ui/undo/undoblk.cxx20
1 files changed, 17 insertions, 3 deletions
diff --git a/sc/source/ui/undo/undoblk.cxx b/sc/source/ui/undo/undoblk.cxx
index cd96fa833f21..fbe1d4557213 100644
--- a/sc/source/ui/undo/undoblk.cxx
+++ b/sc/source/ui/undo/undoblk.cxx
@@ -1626,7 +1626,12 @@ ScDocumentUniquePtr ScUndoConditionalFormat::createUndoRedoData()
ScDocumentUniquePtr pUndoRedoDoc(new ScDocument(SCDOCMODE_UNDO));
pUndoRedoDoc->InitUndo(rDoc, mnTab, mnTab);
if (const auto* pList = rDoc.GetCondFormList(mnTab))
+ {
pUndoRedoDoc->SetCondFormList(new ScConditionalFormatList(*pUndoRedoDoc, *pList), mnTab);
+ // Save CF keys in cells' attributes
+ for (const auto& range : pList->GetCombinedRange())
+ rDoc.CopyToDocument(range, InsertDeleteFlags::ATTRIB, false, *pUndoRedoDoc);
+ }
return pUndoRedoDoc;
}
@@ -1654,14 +1659,23 @@ void ScUndoConditionalFormat::DoChange(ScDocument* pSrcDoc)
// formats with the other formats in the tab, to get the correct state.
ScRangeList aCombinedRange;
if (const auto* pOldList = rDoc.GetCondFormList(mnTab))
+ {
aCombinedRange = pOldList->GetCombinedRange();
+ // Clear all existing CF keys from cells' attributes
+ for (auto& pFormat : *pOldList)
+ rDoc.RemoveCondFormatData(aCombinedRange, mnTab, pFormat->GetKey());
+ }
if (const auto* pNewList = pSrcDoc->GetCondFormList(mnTab))
{
- for (const auto& cond : *pNewList)
- for (const auto& range : cond->GetRange())
- aCombinedRange.Join(range);
+ ScRangeList aCombinedRange2 = pNewList->GetCombinedRange();
rDoc.SetCondFormList(new ScConditionalFormatList(rDoc, *pNewList), mnTab);
+ for (const auto& range : aCombinedRange2)
+ {
+ aCombinedRange.Join(range);
+ // Restore the CF keys to cell attributes
+ pSrcDoc->CopyToDocument(range, InsertDeleteFlags::ATTRIB, false, rDoc);
+ }
}
else
{