sc/qa/unit/uicalc/uicalc.cxx | 39 +++++++++++++++++++++++++++++++++++++++ sc/source/core/data/document.cxx | 8 +++++++- 2 files changed, 46 insertions(+), 1 deletion(-)
New commits: commit 9a2c38530dd5e479a96953980ee7f6c448dce87a Author: Andreas Heinisch <andreas.heini...@yahoo.de> AuthorDate: Thu Sep 26 10:31:41 2024 +0200 Commit: Andreas Heinisch <andreas.heini...@yahoo.de> CommitDate: Fri Oct 4 18:56:08 2024 +0200 tdf#163019 - Remove the formula of a cell during paste special Remove the formula of a cell during paste special and not only the required for insertion. Otherwise, the formula listeners are not updated correctly leading to a crash during the repaint process. Change-Id: I4bf1410ecc7b25e36e1cc91bc0cd5335decb1cae Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173975 Tested-by: Jenkins Reviewed-by: Andreas Heinisch <andreas.heini...@yahoo.de> diff --git a/sc/qa/unit/uicalc/uicalc.cxx b/sc/qa/unit/uicalc/uicalc.cxx index 68a4289417af..76d55137e98b 100644 --- a/sc/qa/unit/uicalc/uicalc.cxx +++ b/sc/qa/unit/uicalc/uicalc.cxx @@ -2311,6 +2311,45 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf141440) CPPUNIT_ASSERT_EQUAL(u"Note in A1"_ustr, pDoc->GetNote(ScAddress(0, 0, 0))->GetText()); } +CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf163019) +{ + createScDoc(); + ScDocument* pDoc = getScDoc(); + + // Disable replace cell warning + ScModule* pMod = SC_MOD(); + ScInputOptions aInputOption = pMod->GetInputOptions(); + bool bOldStatus = aInputOption.GetReplaceCellsWarn(); + aInputOption.SetReplaceCellsWarn(false); + pMod->SetInputOptions(aInputOption); + + // Insert test data and formulas to create a sample crash document + insertStringToCell(u"B1"_ustr, u"1"); + insertStringToCell(u"A2"_ustr, u"1"); + insertStringToCell(u"A3"_ustr, u"1"); + insertStringToCell(u"B2"_ustr, u"=B1-A2"); + insertStringToCell(u"B3"_ustr, u"=B2-A3"); + + // Copy content from B2 to B2 using paste special command as a number (Flags ????) + goToCell(u"B2"_ustr); + dispatchCommand(mxComponent, u".uno:Copy"_ustr, {}); + goToCell(u"B2"_ustr); + uno::Sequence<beans::PropertyValue> aArgs = comphelper::InitPropertySequence( + { { "Flags", uno::Any(u"V"_ustr) }, + { "FormulaCommand", uno::Any(sal_uInt16(ScPasteFunc::NONE)) }, + { "SkipEmptyCells", uno::Any(false) }, + { "Transpose", uno::Any(false) }, + { "AsLink", uno::Any(false) }, + { "MoveMode", uno::Any(sal_uInt16(InsCellCmd::INS_NONE)) } }); + // Without the fix in place, this test would have crashed here + dispatchCommand(mxComponent, u".uno:InsertContents"_ustr, aArgs); + CPPUNIT_ASSERT_EQUAL(u"0"_ustr, pDoc->GetString(ScAddress(1, 1, 0))); + + // Restore previous replace cell warning status + aInputOption.SetReplaceCellsWarn(bOldStatus); + pMod->SetInputOptions(aInputOption); +} + CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf158551) { createScDoc(); diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx index bbce2d15031b..f1ff4241413d 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -2899,7 +2899,13 @@ void ScDocument::CopyFromClip( these cells. In this case, just delete old notes from the destination area. */ InsertDeleteFlags nDelFlag = nInsFlag; - if ( (nInsFlag & (InsertDeleteFlags::CONTENTS | InsertDeleteFlags::ADDNOTES)) == (InsertDeleteFlags::NOTE | InsertDeleteFlags::ADDNOTES) ) + // tdf#163019 - remove formula of the cell to update formula listeners + if (nInsFlag & InsertDeleteFlags::CONTENTS) + nDelFlag |= InsertDeleteFlags::FORMULA; + + // tdf#161189 - remove the note deletion flag if no notes are included + if ((nInsFlag & (InsertDeleteFlags::CONTENTS | InsertDeleteFlags::ADDNOTES)) + == (InsertDeleteFlags::NOTE | InsertDeleteFlags::ADDNOTES)) nDelFlag &= ~InsertDeleteFlags::NOTE; if (nInsFlag & InsertDeleteFlags::ATTRIB)