sc/qa/unit/uicalc/uicalc.cxx | 39 +++++++++++++++++++++++++++++++++++++++ sc/source/core/data/document.cxx | 8 +++++++- 2 files changed, 46 insertions(+), 1 deletion(-)
New commits: commit 62923e5fb48a52754c57100442c61a3170b93fa5 Author: Andreas Heinisch <andreas.heini...@yahoo.de> AuthorDate: Thu Sep 26 10:31:41 2024 +0200 Commit: Christian Lohmaier <lohmaier+libreoff...@googlemail.com> CommitDate: Mon Oct 28 14:01:54 2024 +0100 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> (cherry picked from commit 9a2c38530dd5e479a96953980ee7f6c448dce87a) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174450 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175651 Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175664 Reviewed-by: Adolfo Jayme Barrientos <fit...@ubuntu.com> Tested-by: Christian Lohmaier <lohmaier+libreoff...@googlemail.com> Reviewed-by: Christian Lohmaier <lohmaier+libreoff...@googlemail.com> diff --git a/sc/qa/unit/uicalc/uicalc.cxx b/sc/qa/unit/uicalc/uicalc.cxx index 15795baceaa1..30ca92ffee0c 100644 --- a/sc/qa/unit/uicalc/uicalc.cxx +++ b/sc/qa/unit/uicalc/uicalc.cxx @@ -2078,6 +2078,45 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf141440) CPPUNIT_ASSERT_EQUAL(OUString("Note in A1"), 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("B1", u"1"); + insertStringToCell("A2", u"1"); + insertStringToCell("A3", u"1"); + insertStringToCell("B2", u"=B1-A2"); + insertStringToCell("B3", u"=B2-A3"); + + // Copy content from B2 to B2 using paste special command as a number (Flags ????) + goToCell("B2"); + dispatchCommand(mxComponent, ".uno:Copy", {}); + goToCell("B2"); + uno::Sequence<beans::PropertyValue> aArgs = comphelper::InitPropertySequence( + { { "Flags", uno::Any(OUString("V")) }, + { "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, ".uno:InsertContents", aArgs); + CPPUNIT_ASSERT_EQUAL(OUString("0"), pDoc->GetString(ScAddress(1, 1, 0))); + + // Restore previous replace cell warning status + aInputOption.SetReplaceCellsWarn(bOldStatus); + pMod->SetInputOptions(aInputOption); +} + CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testKeyboardMergeRef) { createScDoc(); diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx index 92609e2dce4f..23d24a8165e3 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -2908,7 +2908,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)