sc/qa/unit/tiledrendering/data/tdf167042.ods  |binary
 sc/qa/unit/tiledrendering/tiledrendering2.cxx |   52 ++++++++++++++++++++++++++
 sc/source/ui/undo/undoblk.cxx                 |    6 ++-
 3 files changed, 56 insertions(+), 2 deletions(-)

New commits:
commit 3e528101c3593eedaea492d03831630b03e933dd
Author:     Balazs Varga <[email protected]>
AuthorDate: Tue Sep 23 13:50:24 2025 +0200
Commit:     Xisco Fauli <[email protected]>
CommitDate: Wed Sep 24 22:01:53 2025 +0200

    tdf#167042 - sc cell comments texts should not be deleted
    
    but the note text should be remembered in maNoteData to be able
    to later reconstruct a caption from it.
    
    Originally the bPreserveData was introduced and set to true in commit:
    b8b657123cc508c906622d20669507628c93e104
    (tdf#104967 preserve isolated notes data in clipboard when closing document)
    The original bugdoc from tdf#104967 was checked with this patch and
    had no crash with it.
    
    Change-Id: I3b6c56e4828c11c2cab0351c95dd4bcb5762d86e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191396
    Tested-by: Jenkins
    Reviewed-by: Balazs Varga <[email protected]>
    (cherry picked from commit 01765ffe843953bbf7d1e2822512306d3776b3be)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191461
    Reviewed-by: Xisco Fauli <[email protected]>

diff --git a/sc/qa/unit/tiledrendering/data/tdf167042.ods 
b/sc/qa/unit/tiledrendering/data/tdf167042.ods
new file mode 100644
index 000000000000..22e95e0597ef
Binary files /dev/null and b/sc/qa/unit/tiledrendering/data/tdf167042.ods differ
diff --git a/sc/qa/unit/tiledrendering/tiledrendering2.cxx 
b/sc/qa/unit/tiledrendering/tiledrendering2.cxx
index ff6ed1881542..cfcbc5a4c768 100644
--- a/sc/qa/unit/tiledrendering/tiledrendering2.cxx
+++ b/sc/qa/unit/tiledrendering/tiledrendering2.cxx
@@ -21,6 +21,7 @@
 #include <docuno.hxx>
 #include <scmod.hxx>
 #include <tabvwsh.hxx>
+#include <postit.hxx>
 
 using namespace com::sun::star;
 
@@ -201,6 +202,57 @@ CPPUNIT_TEST_FIXTURE(ScTiledRenderingTest, 
testSplitPanesXLSX)
     assertXPath(pSheet, "/x:worksheet/x:sheetViews/x:sheetView/x:pane", 
"activePane", u"topRight");
 }
 
+CPPUNIT_TEST_FIXTURE(ScTiledRenderingTest, testTdf167042)
+{
+    ScModelObj* pModelObj = createDoc("tdf167042.ods");
+    ScDocument* pDoc = pModelObj->GetDocument();
+    ScTestViewCallback aView1;
+
+    uno::Sequence<beans::PropertyValue> aPropertyValues
+        = { comphelper::makePropertyValue("ToPoint", OUString("$A$1")) };
+    dispatchCommand(mxComponent, ".uno:GoToCell", aPropertyValues);
+
+    Point aPoint = aView1.m_aCellCursorBounds.Center();
+
+    aPropertyValues = { comphelper::makePropertyValue("ToPoint", 
OUString("$B$1")) };
+    dispatchCommand(mxComponent, ".uno:GoToCell", aPropertyValues);
+
+    // Check that we have the comment on A1
+    CPPUNIT_ASSERT_MESSAGE("There should be a note on A1", 
pDoc->HasNote(ScAddress(0, 0, 0)));
+    ScPostIt* pNote = pDoc->GetNote(ScAddress(0, 0, 0));
+    CPPUNIT_ASSERT(pNote);
+    CPPUNIT_ASSERT_EQUAL(u"test1"_ustr, pNote->GetText());
+
+    uno::Sequence aArgs{ comphelper::makePropertyValue(u"PersistentCopy"_ustr, 
false) };
+    dispatchCommand(mxComponent, u".uno:FormatPaintbrush"_ustr, aArgs);
+
+    pModelObj->postMouseEvent(LOK_MOUSEEVENT_MOUSEBUTTONDOWN, aPoint.getX(), 
aPoint.getY(), 1,
+                              MOUSE_LEFT, 0);
+    pModelObj->postMouseEvent(LOK_MOUSEEVENT_MOUSEBUTTONUP, aPoint.getX(), 
aPoint.getY(), 1,
+                              MOUSE_LEFT, 0);
+
+    // Check that FormatPaintbrush worked
+    vcl::Font aFont;
+    pDoc->GetPattern(0, 0, 0)->fillFontOnly(aFont);
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be bold A1", WEIGHT_BOLD,
+                                 aFont.GetWeightMaybeAskConfig());
+
+    // Check that we still have the comment on A1 after FormatPaintbrush
+    pNote = pDoc->GetNote(ScAddress(0, 0, 0));
+    CPPUNIT_ASSERT(pNote);
+    CPPUNIT_ASSERT_EQUAL(u"test1"_ustr, pNote->GetText());
+
+    dispatchCommand(mxComponent, u".uno:Undo"_ustr, {});
+
+    // Check that we still have the comment on A1 after Undo
+    pNote = pDoc->GetNote(ScAddress(0, 0, 0));
+    CPPUNIT_ASSERT(pNote);
+    // Without the fix in place, this test would have failed with
+    // - Expected : test1
+    // - Actual :
+    CPPUNIT_ASSERT_EQUAL(u"test1"_ustr, pNote->GetText());
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/undo/undoblk.cxx b/sc/source/ui/undo/undoblk.cxx
index 4fa1085f2748..9f4966e80cdf 100644
--- a/sc/source/ui/undo/undoblk.cxx
+++ b/sc/source/ui/undo/undoblk.cxx
@@ -1022,8 +1022,10 @@ void ScUndoPaste::DoChange(bool bUndo)
 
     sal_uInt16 nExtFlags = 0;
     rDocShell.UpdatePaintExt(nExtFlags, maBlockRanges.Combine());
-
-    rDoc.ForgetNoteCaptions(maBlockRanges, false);
+    // tdf#167042 - cell comments texts should not be deleted but
+    // the note text should be remembered in maNoteData to be able
+    // to later reconstruct a caption from it.
+    rDoc.ForgetNoteCaptions(maBlockRanges, true);
     aMarkData.MarkToMulti();
     rDoc.DeleteSelection(nUndoFlags, aMarkData, false); // no broadcasting here
     for (size_t i = 0, n = maBlockRanges.size(); i < n; ++i)

Reply via email to