sc/qa/unit/tiledrendering/data/tdf167042.ods |binary sc/qa/unit/tiledrendering/tiledrendering.cxx | 41 +++++++++++++++++++++++++++ sc/source/ui/undo/undoblk.cxx | 6 ++- 3 files changed, 45 insertions(+), 2 deletions(-)
New commits: commit c36df21baf4803e635f590c7f3a0a1eb5eae74bb Author: Balazs Varga <[email protected]> AuthorDate: Tue Sep 23 13:50:24 2025 +0200 Commit: Gabor Kelemen <[email protected]> CommitDate: Thu Sep 25 21:03:34 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. cherry-pick from: 01765ffe843953bbf7d1e2822512306d3776b3be Change-Id: I3b6c56e4828c11c2cab0351c95dd4bcb5762d86e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191396 Tested-by: Jenkins Reviewed-by: Balazs Varga <[email protected]> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191479 Tested-by: Gabor Kelemen <[email protected]> Reviewed-by: Gabor Kelemen <[email protected]> Tested-by: allotropia jenkins <[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/tiledrendering.cxx b/sc/qa/unit/tiledrendering/tiledrendering.cxx index 02b6783bfe44..16945f259b22 100644 --- a/sc/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx @@ -3992,6 +3992,47 @@ CPPUNIT_TEST_FIXTURE(ScTiledRenderingTest, testLeftOverflowEdit) CPPUNIT_ASSERT_EQUAL(tools::Long(20), aView.m_aTextSelectionResult.m_aRefPoint.getX()); } +CPPUNIT_TEST_FIXTURE(ScTiledRenderingTest, testTdf167042) +{ + ScModelObj* pModelObj = createDoc("tdf167042.ods"); + ScDocument* pDoc = pModelObj->GetDocument(); + ViewCallback 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.GetWeight()); + // 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 cd96fa833f21..9da5d5077cc8 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; pDocShell->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)
