sc/source/ui/undo/undoblk.cxx | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-)
New commits: commit 21830c58f27977ca4a1dbacd2f41583c9f3ae775 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Tue Jan 21 23:54:20 2025 +0500 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Wed Jan 22 05:32:26 2025 +0100 tdf#164785: restore saving/reapplying of CF keys in cells Commit c492de66a077f3a2a960209b0b8b278b3901f361 (tdf#160149: save and restore the whole set of tab's conditional formats, 2024-03-17) had replaced copying of the affected cell ranges (including respective CF) with copying of the whole CF list. That allowed to replace the list as a whole, and be sure that it is in the same state as before the undone operation (not merged in any way because of re-application of CF). But the previous code made sure to set the CF keys in affected cells. New code didn't do that, and so, the changes to the cell attributes with CF keys were not cleared on undo. Applying new CF to another cell range created the same key that was already referenced in those old cells, so they behaved as if they belong to the new CF range. This change keeps the "save/restore whole CF list" idea, so tdf#160149 is kept fixed. But additionally, it restores saving/reapplying of cell attributes (but not other data) in the areas affected by CF. Change-Id: I4ff844ca1345322e231df605fb019b9613a6b123 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180555 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> 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 {