summaryrefslogtreecommitdiff
path: root/sw/qa/extras/unowriter
diff options
context:
space:
mode:
authorMichael Stahl <Michael.Stahl@cib.de>2020-04-09 18:31:50 +0200
committerMichael Stahl <michael.stahl@cib.de>2020-04-14 16:59:00 +0200
commit971205dc2110c1c23ff1db1fc4041e2babf6fa9f (patch)
tree206e18ddc8ee58be806c59ed4e78724550647498 /sw/qa/extras/unowriter
parent11785217594d863efb518aa8b8f2910cdcb9c59d (diff)
sw: fix fly at-char deletion API behaviour change
28b77c89dfcafae82cf2a6d85731b643ff9290e5 changed at-char anchored fly selection. WollMux calls setString("") to remove one character in the first paragraph and a fly anchored at the start of the body text is deleted due to the new IsAtStartOfSection() check. It would be possible to treat deletion via API differently than via UI, as there is already a flag ExcludeFlyAtStartEnd but it would require passing the flag through 10 functions and also to store it in SwUndoDelete... The main intent of the IsAtStartOfSection() check was that Ctrl+A should delete every fly; this can be achieved by checking that everything was selected, so that selections only inside the first/last paragraph don't delete the flys at the edges. Change-Id: Id62e7d99a10b42eaecea5564372d29b6c43e3f7e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91993 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@cib.de>
Diffstat (limited to 'sw/qa/extras/unowriter')
-rw-r--r--sw/qa/extras/unowriter/unowriter.cxx51
1 files changed, 51 insertions, 0 deletions
diff --git a/sw/qa/extras/unowriter/unowriter.cxx b/sw/qa/extras/unowriter/unowriter.cxx
index 4f4c93a13f01..6e67892a027f 100644
--- a/sw/qa/extras/unowriter/unowriter.cxx
+++ b/sw/qa/extras/unowriter/unowriter.cxx
@@ -16,6 +16,7 @@
#include <com/sun/star/text/XAutoTextGroup.hpp>
#include <com/sun/star/text/XTextPortionAppend.hpp>
#include <com/sun/star/text/XTextContentAppend.hpp>
+#include <com/sun/star/text/XTextRangeCompare.hpp>
#include <com/sun/star/rdf/URI.hpp>
#include <com/sun/star/rdf/URIs.hpp>
#include <com/sun/star/awt/XDevice.hpp>
@@ -454,6 +455,56 @@ CPPUNIT_TEST_FIXTURE(SwUnoWriter, testSetPagePrintSettings)
CPPUNIT_ASSERT_EQUAL(true, aMap.getValue("IsLandscape").get<bool>());
}
+CPPUNIT_TEST_FIXTURE(SwUnoWriter, testDeleteFlyAtCharAtStart)
+{
+ loadURL("private:factory/swriter", nullptr);
+ SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+ CPPUNIT_ASSERT(pTextDoc);
+ SwWrtShell* const pWrtShell(pTextDoc->GetDocShell()->GetWrtShell());
+ SwDoc* const pDoc(pWrtShell->GetDoc());
+
+ // insert some text
+ IDocumentContentOperations& rIDCO(pDoc->getIDocumentContentOperations());
+ rIDCO.InsertString(*pWrtShell->GetCursor(), "foo bar baz");
+
+ // insert fly anchored at start of body text
+ pWrtShell->ClearMark();
+ pWrtShell->SttEndDoc(true);
+ SfxItemSet frameSet(pDoc->GetAttrPool(), svl::Items<RES_FRMATR_BEGIN, RES_FRMATR_END - 1>{});
+ SfxItemSet grfSet(pDoc->GetAttrPool(), svl::Items<RES_GRFATR_BEGIN, RES_GRFATR_END - 1>{});
+ SwFormatAnchor anchor(RndStdIds::FLY_AT_CHAR);
+ frameSet.Put(anchor);
+ GraphicObject grf;
+ CPPUNIT_ASSERT(rIDCO.InsertGraphicObject(*pWrtShell->GetCursor(), grf, &frameSet, &grfSet));
+
+ // check fly
+ uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
+ uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage();
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xDrawPage->getCount());
+ uno::Reference<text::XTextContent> const xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
+ // anchored at start of body text?
+ uno::Reference<text::XText> const xText(pTextDoc->getText());
+ uno::Reference<text::XTextRangeCompare> const xTextRC(xText, uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(0),
+ xTextRC->compareRegionStarts(xText->getStart(), xShape->getAnchor()));
+
+ // delete 1st character
+ uno::Reference<text::XTextCursor> const xCursor(xText->createTextCursor());
+ xCursor->goRight(1, true);
+ xCursor->setString("");
+
+ // there is exactly one fly
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xDrawPage->getCount());
+
+ // select entire body text
+ xCursor->gotoStart(true);
+ xCursor->gotoEnd(true);
+ xCursor->setString("");
+
+ // there is no fly
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xDrawPage->getCount());
+}
+
CPPUNIT_TEST_FIXTURE(SwUnoWriter, testSelectionInTableEnum)
{
load(mpTestDocumentPath, "selection-in-table-enum.odt");