sc/qa/unit/ucalc_copypaste.cxx   |   14 ++++++--------
 sc/qa/unit/uicalc/uicalc.cxx     |   39 +++++++++++++++++++++++++++++++++++++++
 sc/source/core/data/document.cxx |   15 +++++++++------
 3 files changed, 54 insertions(+), 14 deletions(-)

New commits:
commit 0e5b3ce4342441e3ab3d74ba9abfb25ab34d1b3b
Author:     Andreas Heinisch <andreas.heini...@yahoo.de>
AuthorDate: Thu Sep 26 10:31:41 2024 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Fri Oct 25 21:37:23 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>
    (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

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)
commit 81b785b66b654b29704d9cd6f79b01274f73c189
Author:     Andreas Heinisch <andreas.heini...@yahoo.de>
AuthorDate: Sat Jul 20 21:45:34 2024 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Fri Oct 25 21:37:17 2024 +0200

    tdf#161189 - CopyFromClip: improve handling of deleting notes
    
    Instead of adding additional deletion flags, just remove the note 
deletetion flag when needed.
    
    Change-Id: Iba0dd4f922694c9fff98f4b74bccad1b8ee16d49
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170803
    Tested-by: Jenkins
    Reviewed-by: Andreas Heinisch <andreas.heini...@yahoo.de>
    (cherry picked from commit e747986af4dbb6b48957092dadce26a95b910a82)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172128
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>
    (cherry picked from commit 70a34d6b8bb4a4ecc89f1ceafaa2ea5d3a67acf8)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172132
    Tested-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sc/qa/unit/ucalc_copypaste.cxx b/sc/qa/unit/ucalc_copypaste.cxx
index bec9bb499b94..1c1bd833b5d8 100644
--- a/sc/qa/unit/ucalc_copypaste.cxx
+++ b/sc/qa/unit/ucalc_copypaste.cxx
@@ -9408,11 +9408,10 @@ CPPUNIT_TEST_FIXTURE(TestCopyPaste, 
testCopyPasteSkipEmpty)
 
     // Check the content after the paste.
     {
-        // tdf#141440 - do not delete notes when pasting contents
         static const Check aChecks[] = {
-            { "Clip1", COL_YELLOW, true }, { "B", COL_BLUE, true },
-            { "Clip2", COL_YELLOW, true }, { "D", COL_BLUE, true },
-            { "Clip3", COL_YELLOW, true },
+            { "Clip1", COL_YELLOW, false }, { "B", COL_BLUE, true },
+            { "Clip2", COL_YELLOW, false }, { "D", COL_BLUE, true },
+            { "Clip3", COL_YELLOW, false },
         };
 
         bool bRes
@@ -9436,11 +9435,10 @@ CPPUNIT_TEST_FIXTURE(TestCopyPaste, 
testCopyPasteSkipEmpty)
     // Redo, and check the content again.
     aUndo.Redo();
     {
-        // tdf#141440 - do not delete notes when pasting contents
         static const Check aChecks[] = {
-            { "Clip1", COL_YELLOW, true }, { "B", COL_BLUE, true },
-            { "Clip2", COL_YELLOW, true }, { "D", COL_BLUE, true },
-            { "Clip3", COL_YELLOW, true },
+            { "Clip1", COL_YELLOW, false }, { "B", COL_BLUE, true },
+            { "Clip2", COL_YELLOW, false }, { "D", COL_BLUE, true },
+            { "Clip3", COL_YELLOW, false },
         };
 
         bool bRes
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 2bca3a798fb1..92609e2dce4f 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -2907,12 +2907,9 @@ void ScDocument::CopyFromClip(
         overwrite/delete existing cells but to insert the notes into
         these cells. In this case, just delete old notes from the
         destination area. */
-    InsertDeleteFlags nDelFlag = InsertDeleteFlags::NONE;
+    InsertDeleteFlags nDelFlag = nInsFlag;
     if ( (nInsFlag & (InsertDeleteFlags::CONTENTS | 
InsertDeleteFlags::ADDNOTES)) == (InsertDeleteFlags::NOTE | 
InsertDeleteFlags::ADDNOTES) )
-        nDelFlag |= InsertDeleteFlags::NOTE;
-    // tdf#141440 - do not delete notes when pasting contents (see 
InsertDeleteFlags::CONTENTS)
-    else if ( nInsFlag & (InsertDeleteFlags::CONTENTS & 
~InsertDeleteFlags::NOTE) )
-        nDelFlag |= InsertDeleteFlags::CONTENTS & ~InsertDeleteFlags::NOTE;
+        nDelFlag &= ~InsertDeleteFlags::NOTE;
 
     if (nInsFlag & InsertDeleteFlags::ATTRIB)
         nDelFlag |= InsertDeleteFlags::ATTRIB;

Reply via email to