summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-06-24 10:46:40 +0200
committerAndras Timar <andras.timar@collabora.com>2022-06-27 19:26:47 +0200
commit8db2090059c79599c71493bc19536558c85d2975 (patch)
treeca2131ba452ef96ef091b41bed58fb1781ec5bcc
parent2b567b9f3c06349ecb368c2592fd48599c91bb56 (diff)
tdf#148522 svx: fix undo of cell border changes text alignment in other cells
The Impress table properties dialog has multiple purposes: normally it only affects the properties of the currently active cell, but shadow is applied on the whole shape. Regression from commit fdeb04f7c59cf8032fe17072ed779e70505cc6ab (tdf#129961 svx: finish UI for table shadow as direct format, 2020-12-15), we started to apply properties to the current cell, and then to the whole shape as well, unconditionally. This affects undo/redo, as there is a separate undo manager while the text edit of a table cell is active and when the text edit is ended. Fix the problem by only applying properties on the shape when there we actually have some properties: this way the text edit is typically not ended, bringing back the old undo/redo behavior. Note that we still need to end the text edit if the user explicitly sets some shadow properties, that part is unchanged with this commit. Change-Id: I78e28bd326a2c12c3775b33957adca4cd95ac582 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136357 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins (cherry picked from commit 3edfbc19950610bb2061d29cb58b3811b1a0b1a5) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136460 Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org> (cherry picked from commit 750568d77812202c9c01fa87945b507a358c6db5) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136468
-rw-r--r--svx/qa/unit/table.cxx38
-rw-r--r--svx/source/table/tablecontroller.cxx7
2 files changed, 45 insertions, 0 deletions
diff --git a/svx/qa/unit/table.cxx b/svx/qa/unit/table.cxx
index c82f331f2d17..c68abe18beea 100644
--- a/svx/qa/unit/table.cxx
+++ b/svx/qa/unit/table.cxx
@@ -24,6 +24,11 @@
#include <svx/unopage.hxx>
#include <vcl/virdev.hxx>
#include <sdr/contact/objectcontactofobjlistpainter.hxx>
+#include <comphelper/propertyvalue.hxx>
+#include <sfx2/viewsh.hxx>
+#include <svx/svdview.hxx>
+#include <svx/sdr/table/tablecontroller.hxx>
+#include <editeng/editobj.hxx>
using namespace ::com::sun::star;
@@ -99,6 +104,39 @@ CPPUNIT_TEST_FIXTURE(Test, testTableShadowBlur)
// itself and the transparency of the cell fill.
assertXPath(pDocument, "//objectinfo/unifiedtransparence[1]", "transparence", "80");
}
+
+CPPUNIT_TEST_FIXTURE(Test, testSvxTableControllerSetAttrToSelectedShape)
+{
+ // Given a document with a table shape, editing cell text:
+ getComponent() = loadFromDesktop("private:factory/simpress",
+ "com.sun.star.presentation.PresentationDocument");
+ uno::Sequence<beans::PropertyValue> aArgs
+ = { comphelper::makePropertyValue("Rows", sal_Int32(2)),
+ comphelper::makePropertyValue("Columns", sal_Int32(2)) };
+ dispatchCommand(mxComponent, ".uno:InsertTable", aArgs);
+ uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(getComponent(), uno::UNO_QUERY);
+ uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
+ uno::UNO_QUERY);
+ auto pDrawPage = dynamic_cast<SvxDrawPage*>(xDrawPage.get());
+ CPPUNIT_ASSERT(pDrawPage);
+ SdrPage* pSdrPage = pDrawPage->GetSdrPage();
+ auto pSdrObject
+ = dynamic_cast<sdr::table::SdrTableObj*>(pSdrPage->GetObj(pSdrPage->GetObjCount() - 1));
+ SfxViewShell* pViewShell = SfxViewShell::Current();
+ SdrView* pSdrView = pViewShell->GetDrawView();
+ pSdrView->SdrBeginTextEdit(pSdrObject);
+ CPPUNIT_ASSERT(pSdrView->IsTextEdit());
+ const EditTextObject& rEdit = pSdrObject->getText(0)->GetOutlinerParaObject()->GetTextObject();
+ SfxItemSet aSet(rEdit.GetParaAttribs(0));
+ auto pTableController
+ = dynamic_cast<sdr::table::SvxTableController*>(pSdrView->getSelectionController().get());
+
+ // When applying attributes which only affect the cell text, not the table shape:
+ pTableController->SetAttrToSelectedShape(aSet);
+
+ // Then make sure the text edit is not ended:
+ CPPUNIT_ASSERT(pSdrView->IsTextEdit());
+}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/table/tablecontroller.cxx b/svx/source/table/tablecontroller.cxx
index d11b22988148..42712b09296f 100644
--- a/svx/source/table/tablecontroller.cxx
+++ b/svx/source/table/tablecontroller.cxx
@@ -2752,6 +2752,13 @@ void SvxTableController::SetAttrToSelectedShape(const SfxItemSet& rAttr)
SfxItemSetFixed<SDRATTR_SHADOW_FIRST, SDRATTR_SHADOW_LAST> aSet(*rAttr.GetPool());
aSet.Put(rAttr);
+ if (!aSet.Count())
+ {
+ // If there are no items to be applied on the shape, then don't set anything, it would
+ // terminate text edit without a good reason, which affects undo/redo.
+ return;
+ }
+
// Set shadow items on the marked shape.
mrView.SetAttrToMarked(aSet, /*bReplaceAll=*/false);
}