diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2021-03-26 09:30:18 +0100 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2021-03-30 15:16:57 +0200 |
commit | 795005f210e74bf04be798609ca1d4d93be74061 (patch) | |
tree | 880b233809d2381597411f1bd24e9e31eeb57e63 | |
parent | 09afa34955d76419ebe8f4d15780d801f95256ca (diff) |
Don't end text editing in other views if shape inserted
This is revert of a small piece of
tdf#126180: EndTextEdit on all views before delete/cut slide
e6c7a018a0cfee395ce2886d41c908a2447ef5cc
Change needed for online where multiple users work together
and we need to not disturb other views in editing.
Change-Id: I73c2289a9d950465f020f684e9e736148380f5c5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113148
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Jan Holesovsky <kendy@collabora.com>
-rw-r--r-- | include/svx/svdedtv.hxx | 6 | ||||
-rw-r--r-- | sd/qa/unit/tiledrendering/tiledrendering.cxx | 51 | ||||
-rw-r--r-- | svx/source/svdraw/svdedtv.cxx | 21 |
3 files changed, 74 insertions, 4 deletions
diff --git a/include/svx/svdedtv.hxx b/include/svx/svdedtv.hxx index 4351ccee2764..51da6124ed88 100644 --- a/include/svx/svdedtv.hxx +++ b/include/svx/svdedtv.hxx @@ -186,6 +186,12 @@ public: bool IsUndoEnabled() const; /** + * Checks if this or other views have an active text edit, in which case object undos are not + * created. + */ + bool CanDoSdrUndo() const; + + /** * Checks if this or other views have an active text edit, if true, end them. */ void EndTextEditAllViews() const; diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx index 61940c1e8c2a..161aed640277 100644 --- a/sd/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx @@ -114,6 +114,7 @@ public: void testCommentChangeDraw(); void testMultiViewInsertDeletePage(); void testMultiViewInsertDeletePage2(); + void testEditingTextBoxAndInsertShapeInterrupt(); void testDisableUndoRepair(); void testDocumentRepair(); void testLanguageStatus(); @@ -167,6 +168,7 @@ public: CPPUNIT_TEST(testCommentChangeDraw); CPPUNIT_TEST(testMultiViewInsertDeletePage); CPPUNIT_TEST(testMultiViewInsertDeletePage2); + CPPUNIT_TEST(testEditingTextBoxAndInsertShapeInterrupt); CPPUNIT_TEST(testDisableUndoRepair); CPPUNIT_TEST(testDocumentRepair); CPPUNIT_TEST(testLanguageStatus); @@ -1986,6 +1988,55 @@ void SdTiledRenderingTest::testMultiViewInsertDeletePage2() CPPUNIT_ASSERT(pViewShell->GetView()->IsTextEdit()); } +void SdTiledRenderingTest::testEditingTextBoxAndInsertShapeInterrupt() +{ + // Load the document. + SdXImpressDocument* pXImpressDocument = createDoc("dummy.odp"); + ViewCallback aView1; + int nView1 = SfxLokHelper::getView(); + uno::Sequence<beans::PropertyValue> aArgs; + + // Create second view + SfxLokHelper::createView(); + pXImpressDocument->initializeForTiledRendering(aArgs); + ViewCallback aView2; + int nView2 = SfxLokHelper::getView(); + + // Switch to 5th page in 2nd view + pXImpressDocument->setPart(4); + + // Begin text edit on the only object on the slide. + sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell(); + SdPage* pActualPage = pViewShell->GetActualPage(); + SdrObject* pObject1 = pActualPage->GetObj(0); + CPPUNIT_ASSERT(pObject1 != nullptr); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(OBJ_TITLETEXT), pObject1->GetObjIdentifier()); + SdrTextObj* pTextObject = static_cast<SdrTextObj*>(pObject1); + + // Double-click outside the text to enter edit mode. + const ::tools::Rectangle aRect = pTextObject->GetCurrentBoundRect(); + const auto cornerX = convertMm100ToTwip(aRect.getX() + (aRect.getWidth() / 4)); + const auto cornerY = convertMm100ToTwip(aRect.getY() + (aRect.getHeight() / 4)); + pXImpressDocument->postMouseEvent(LOK_MOUSEEVENT_MOUSEBUTTONDOWN, + cornerX, cornerY, + 2, MOUSE_LEFT, 0); + pXImpressDocument->postMouseEvent(LOK_MOUSEEVENT_MOUSEBUTTONUP, + cornerX, cornerY, + 2, MOUSE_LEFT, 0); + Scheduler::ProcessEventsToIdle(); + + // We must be in text editing mode and have cursor visible. + CPPUNIT_ASSERT(pViewShell->GetView()->IsTextEdit()); + + // Insert shape in 1st view + SfxLokHelper::setView(nView1); + comphelper::dispatchCommand(".uno:BasicShapes.rectangle", aArgs); + + // We must be still in text editing mode and have cursor visible. + SfxLokHelper::setView(nView2); + CPPUNIT_ASSERT(pViewShell->GetView()->IsTextEdit()); +} + void SdTiledRenderingTest::testDisableUndoRepair() { // Load the document. diff --git a/svx/source/svdraw/svdedtv.cxx b/svx/source/svdraw/svdedtv.cxx index b301d19312d2..b48174ad8b57 100644 --- a/svx/source/svdraw/svdedtv.cxx +++ b/svx/source/svdraw/svdedtv.cxx @@ -973,11 +973,8 @@ bool SdrEditView::InsertObjectAtView(SdrObject* pObj, SdrPageView& rPV, SdrInser if (!pObj->IsInserted()) { rPV.GetObjList()->InsertObject(pObj, SAL_MAX_SIZE); } - if( IsUndoEnabled()) - { - EndTextEditAllViews(); + if( IsUndoEnabled() && CanDoSdrUndo()) AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoNewObject(*pObj)); - } if (!(nOptions & SdrInsertFlags::DONTMARK)) { if (!(nOptions & SdrInsertFlags::ADDMARK)) UnmarkAllObj(); @@ -1032,6 +1029,22 @@ bool SdrEditView::IsUndoEnabled() const return mpModel->IsUndoEnabled(); } +bool SdrEditView::CanDoSdrUndo() const +{ + size_t nViews = mpModel->GetListenerCount(); + for (size_t nView = 0; nView < nViews; ++nView) + { + SdrEditView* pView = dynamic_cast<SdrEditView*>(mpModel->GetListener(nView)); + if (!pView) + continue; + + if (pView->IsTextEdit()) + return false; + } + + return true; +} + void SdrEditView::EndTextEditAllViews() const { size_t nViews = mpModel->GetListenerCount(); |