From 5ce2125471ed3dafffbfd04e40ea5274cc548896 Mon Sep 17 00:00:00 2001 From: Eike Rathke Date: Sat, 14 Mar 2020 22:08:52 +0100 Subject: Resolves: tdf#130371 Undo of sheet-local named expressions ... created during paste (and maybe other operations). Change-Id: I75d668f717b7336a1a65a9e02c75bf2aefe860b1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90497 Reviewed-by: Eike Rathke Tested-by: Jenkins --- sc/source/core/data/table2.cxx | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'sc') diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx index 3828476810f2..80aa348ab3eb 100644 --- a/sc/source/core/data/table2.cxx +++ b/sc/source/core/data/table2.cxx @@ -52,6 +52,7 @@ #include #include #include +#include #include #include @@ -1167,6 +1168,14 @@ void ScTable::CopyToTable( return; bool bIsUndoDoc = pDestTab->pDocument->IsUndo(); + + if (bIsUndoDoc && (nFlags & InsertDeleteFlags::CONTENTS)) + { + // Copying formulas may create sheet-local named expressions on the + // destination sheet. Add existings to Undo first. + pDestTab->SetRangeName( std::unique_ptr( new ScRangeName( *GetRangeName()))); + } + if (nFlags != InsertDeleteFlags::NONE) { InsertDeleteFlags nTempFlags( nFlags & @@ -1321,6 +1330,21 @@ void ScTable::UndoToTable( bool bWidth = (nRow1==0 && nRow2==pDocument->MaxRow() && mpColWidth && pDestTab->mpColWidth); bool bHeight = (nCol1==0 && nCol2==pDocument->MaxCol() && mpRowHeights && pDestTab->mpRowHeights); + if ((nFlags & InsertDeleteFlags::CONTENTS) && mpRangeName) + { + // Undo sheet-local named expressions created during copying + // formulas. If mpRangeName is not set then the Undo wasn't even + // set to an empty ScRangeName map so don't "undo" that. + pDestTab->SetRangeName( std::unique_ptr( new ScRangeName( *GetRangeName()))); + if (!pDestTab->pDocument->IsClipOrUndo()) + { + ScDocShell* pDocSh = static_cast(pDestTab->pDocument->GetDocumentShell()); + if (pDocSh) + pDocSh->SetAreasChangedNeedBroadcast(); + } + + } + for ( SCCOL i = 0; i < aCol.size(); i++) { if ( i >= nCol1 && i <= nCol2 ) -- cgit