sd/qa/unit/AnnotationTest.cxx | 31 +++++++++++++++++++++++++++++++ sd/source/core/sdpage2.cxx | 4 +++- 2 files changed, 34 insertions(+), 1 deletion(-)
New commits: commit 2f6cc65bc813ee5df8c6117deaaf7696c6890372 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Mon Sep 30 10:11:38 2024 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Thu Dec 26 11:14:28 2024 +0100 tdf#163144 Undo crash when duplicationg a page with a new annotation Check if the annotation pop-up is set and only if it is, try to close it. Also added a test for this. Change-Id: Id2db041f2c0e917304377a747b1bb31bda0c6f5f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174287 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> (cherry picked from commit f24bb80e45c1693db33b47ee695436b2c8d5fbcd) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179417 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/sd/qa/unit/AnnotationTest.cxx b/sd/qa/unit/AnnotationTest.cxx index a480c023766b..060f81f55526 100644 --- a/sd/qa/unit/AnnotationTest.cxx +++ b/sd/qa/unit/AnnotationTest.cxx @@ -420,6 +420,37 @@ CPPUNIT_TEST_FIXTURE(AnnotationTest, testAnnotationDuplicatePage) } } +CPPUNIT_TEST_FIXTURE(AnnotationTest, testAnnotationDuplicatePageAndUndo) +{ + // Insert annotation, duplicate, undo + + createSdDrawDoc(); + + auto pXImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get()); + sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell(); + CPPUNIT_ASSERT(pViewShell); + auto* pDrawViewShell = dynamic_cast<sd::DrawViewShell*>(pViewShell); + CPPUNIT_ASSERT(pDrawViewShell); + + SdDrawDocument* pDocument = pXImpressDocument->GetDocShell()->GetDoc(); + CPPUNIT_ASSERT(pDocument); + + // Inserted new annotation + uno::Sequence<beans::PropertyValue> aArgs; + + aArgs = comphelper::InitPropertySequence({ + { "Text", uno::Any(u"Comment"_ustr) }, + }); + + dispatchCommand(mxComponent, u".uno:InsertAnnotation"_ustr, aArgs); + + // Duplicate + dispatchCommand(mxComponent, u".uno:DuplicatePage"_ustr, {}); + + // Undo + dispatchCommand(mxComponent, u".uno:Undo"_ustr, {}); +} + CPPUNIT_TEST_FIXTURE(AnnotationTest, testAnnotationTextUpdate) { createSdDrawDoc(); diff --git a/sd/source/core/sdpage2.cxx b/sd/source/core/sdpage2.cxx index 7b0abf63fad7..794b30f2c592 100644 --- a/sd/source/core/sdpage2.cxx +++ b/sd/source/core/sdpage2.cxx @@ -603,7 +603,9 @@ void SdPage::removeAnnotationNoNotify(rtl::Reference<sdr::annotation::Annotation SdrObject* pObject = GetObj(nObjectIndex); if (pObject->isAnnotationObject() && pObject->getAnnotationData()->mxAnnotation == xAnnotation) { - pObject->getAnnotationData()->mpAnnotationPopup->closePopup(); + auto& pAnnotationPopup = pObject->getAnnotationData()->mpAnnotationPopup; + if (pAnnotationPopup) + pAnnotationPopup->closePopup(); RemoveObject(nObjectIndex); } }