include/svx/svdedtv.hxx                      |    2 -
 sc/qa/unit/tiledrendering/tiledrendering.cxx |   33 +++++++++++++++++++++++++--
 svx/source/svdraw/svdedtv.cxx                |    7 +++--
 3 files changed, 36 insertions(+), 6 deletions(-)

New commits:
commit 419e9bd76382f5161a81694c5dbc0784eeda708e
Author:     Szymon Kłos <szymon.k...@collabora.com>
AuthorDate: Wed Mar 9 16:41:36 2022 +0100
Commit:     Szymon Kłos <szymon.k...@collabora.com>
CommitDate: Mon Mar 14 08:42:20 2022 +0100

    svx: don't remove object right after insertion
    
    This is regression from:
    commit 2d95b3846eac367d2baadc194ab258dc31e7bd33
    Author: Tomaz Vajngerl <tomaz.vajng...@collabora.co.uk>
    Date:   Thu Oct 7 16:48:46 2021 +0200
    
        svx: Don't end text edit mode for all views
    
    It was visible with "direct insertion" where user doesn't
    need to draw anything but textbox is inserted in the center
    of a screen (eg. used in LOK case)
    
    Object was inserted into a view and right after that was removed when
    EndTextEditCurrentView was called
    
    Change-Id: I9943d46746aabadf96d76d6e74770b56d648b79d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131263
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Mert Tumer <mert.tu...@collabora.com>

diff --git a/include/svx/svdedtv.hxx b/include/svx/svdedtv.hxx
index cf9955edcb15..87da3dadc39d 100644
--- a/include/svx/svdedtv.hxx
+++ b/include/svx/svdedtv.hxx
@@ -188,7 +188,7 @@ public:
      * Checks if this or other views have an active text edit, if true, end 
them.
      */
     void EndTextEditAllViews() const;
-    void EndTextEditCurrentView();
+    void EndTextEditCurrentView(bool bDontDeleteReally = false);
 
     std::vector< std::unique_ptr<SdrUndoAction> > CreateConnectorUndo( 
SdrObject& rO );
     void AddUndoActions( std::vector< std::unique_ptr<SdrUndoAction> > );
diff --git a/sc/qa/unit/tiledrendering/tiledrendering.cxx 
b/sc/qa/unit/tiledrendering/tiledrendering.cxx
index e7826eb5e227..b9b7e698c081 100644
--- a/sc/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx
@@ -124,6 +124,7 @@ public:
     void testEditCursorBounds();
     void testTextSelectionBounds();
     void testSheetViewDataCrash();
+    void testTextBoxInsert();
 
     CPPUNIT_TEST_SUITE(ScTiledRenderingTest);
     CPPUNIT_TEST(testRowColumnHeaders);
@@ -177,6 +178,7 @@ public:
     CPPUNIT_TEST(testEditCursorBounds);
     CPPUNIT_TEST(testTextSelectionBounds);
     CPPUNIT_TEST(testSheetViewDataCrash);
+    CPPUNIT_TEST(testTextBoxInsert);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -472,7 +474,12 @@ struct EditCursorMessage final {
         std::stringstream aStream(pMessage);
         boost::property_tree::ptree aTree;
         boost::property_tree::read_json(aStream, aTree);
-        std::string aVal = 
aTree.get_child("refpoint").get_value<std::string>();
+        std::string aVal;
+        boost::property_tree::ptree::const_assoc_iterator it = 
aTree.find("refpoint");
+        if (it != aTree.not_found())
+            aVal = aTree.get_child("refpoint").get_value<std::string>();
+        else
+            return; // happens in testTextBoxInsert test
 
         uno::Sequence<OUString> aSeq = 
comphelper::string::convertCommaSeparated(OUString::createFromAscii(aVal.c_str()));
         CPPUNIT_ASSERT_EQUAL(2, aSeq.getLength());
@@ -836,7 +843,7 @@ void ScTiledRenderingTest::testViewLock()
     CPPUNIT_ASSERT(!aView1.m_bViewLock);
 }
 
-static void lcl_extractHandleParameters(const OString& selection, int& id, 
int& x, int& y)
+void lcl_extractHandleParameters(const OString& selection, int& id, int& x, 
int& y)
 {
     OString extraInfo = selection.copy(selection.indexOf("{"));
     std::stringstream aStream(extraInfo.getStr());
@@ -2888,6 +2895,28 @@ void ScTiledRenderingTest::testSheetViewDataCrash()
     Scheduler::ProcessEventsToIdle();
 }
 
+void ScTiledRenderingTest::testTextBoxInsert()
+{
+    comphelper::LibreOfficeKit::setActive();
+
+    createDoc("empty.ods");
+    ViewCallback aView1;
+
+    // insert textbox
+    uno::Sequence<beans::PropertyValue> aArgs(
+        comphelper::InitPropertySequence({
+            { "CreateDirectly",  uno::Any(true) }
+        }));
+    comphelper::dispatchCommand(".uno:DrawText", aArgs);
+    Scheduler::ProcessEventsToIdle();
+
+    // check if we have textbox selected
+    CPPUNIT_ASSERT(!aView1.m_ShapeSelection.isEmpty());
+    CPPUNIT_ASSERT(aView1.m_ShapeSelection != "EMPTY");
+
+    Scheduler::ProcessEventsToIdle();
+}
+
 }
 
 CPPUNIT_TEST_SUITE_REGISTRATION(ScTiledRenderingTest);
diff --git a/svx/source/svdraw/svdedtv.cxx b/svx/source/svdraw/svdedtv.cxx
index 6f2be8bf54f4..b383d2302ce7 100644
--- a/svx/source/svdraw/svdedtv.cxx
+++ b/svx/source/svdraw/svdedtv.cxx
@@ -998,7 +998,8 @@ bool SdrEditView::InsertObjectAtView(SdrObject* pObj, 
SdrPageView& rPV, SdrInser
     }
     if( IsUndoEnabled())
     {
-        EndTextEditCurrentView();
+        bool bDontDeleteReally = true;
+        EndTextEditCurrentView(bDontDeleteReally);
         AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoNewObject(*pObj));
     }
 
@@ -1069,13 +1070,13 @@ void SdrEditView::EndTextEditAllViews() const
     }
 }
 
-void SdrEditView::EndTextEditCurrentView()
+void SdrEditView::EndTextEditCurrentView(bool bDontDeleteReally)
 {
     if (IsTextEdit())
     {
         SdrView* pSdrView = dynamic_cast<SdrView*>(this);
         if (pSdrView)
-            pSdrView->SdrEndTextEdit();
+            pSdrView->SdrEndTextEdit(bDontDeleteReally);
     }
 }
 

Reply via email to