summaryrefslogtreecommitdiffstats
path: root/sc/source/ui/undo/undoblk.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'sc/source/ui/undo/undoblk.cxx')
-rw-r--r--sc/source/ui/undo/undoblk.cxx26
1 files changed, 21 insertions, 5 deletions
diff --git a/sc/source/ui/undo/undoblk.cxx b/sc/source/ui/undo/undoblk.cxx
index d352ba143b..c74d23f6e7 100644
--- a/sc/source/ui/undo/undoblk.cxx
+++ b/sc/source/ui/undo/undoblk.cxx
@@ -1563,11 +1563,11 @@ bool ScUndoListNames::CanRepeat(SfxRepeatTarget& rTarget) const
}
ScUndoConditionalFormat::ScUndoConditionalFormat(ScDocShell* pNewDocShell,
- ScDocumentUniquePtr pUndoDoc, ScDocumentUniquePtr pRedoDoc, const ScRange& rRange):
+ ScDocumentUniquePtr pUndoDoc, ScDocumentUniquePtr pRedoDoc, SCTAB nTab):
ScSimpleUndo( pNewDocShell ),
mpUndoDoc(std::move(pUndoDoc)),
mpRedoDoc(std::move(pRedoDoc)),
- maRange(rRange)
+ mnTab(nTab)
{
}
@@ -1594,9 +1594,25 @@ void ScUndoConditionalFormat::DoChange(ScDocument* pSrcDoc)
{
ScDocument& rDoc = pDocShell->GetDocument();
- rDoc.DeleteAreaTab( maRange, InsertDeleteFlags::ALL );
- pSrcDoc->CopyToDocument(maRange, InsertDeleteFlags::ALL, false, rDoc);
- pDocShell->PostPaint( maRange, PaintPartFlags::Grid );
+ // Restore all conditional formats in the tab. This is simpler and more reliable, than
+ // restoring formats in a specific range, and then trying to join selectively the restored
+ // 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();
+
+ if (const auto* pNewList = pSrcDoc->GetCondFormList(mnTab))
+ {
+ for (const auto& cond : *pNewList)
+ for (const auto& range : cond->GetRange())
+ aCombinedRange.Join(range);
+ rDoc.SetCondFormList(new ScConditionalFormatList(rDoc, *pNewList), mnTab);
+ }
+ else
+ {
+ rDoc.SetCondFormList(nullptr, mnTab);
+ }
+ pDocShell->PostPaint(aCombinedRange, PaintPartFlags::Grid);
pDocShell->PostDataChanged();
ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
if (pViewShell)