[Libreoffice-commits] core.git: Branch 'private/swe/libreoffice-5-2+backports' - sw/qa sw/source
Serge Krot
Serge.Krot at cib.de
Fri Dec 22 18:00:51 UTC 2017
sw/qa/extras/uiwriter/data/tdf113877_insert_numbered_list.odt |binary
sw/qa/extras/uiwriter/uiwriter.cxx | 28 +++
sw/source/filter/xml/xmlimp.cxx | 85 ++++++++++
3 files changed, 113 insertions(+)
New commits:
commit c59e028e5337d1511dbcc678a90ffdbe92a44521
Author: Serge Krot <Serge.Krot at cib.de>
Date: Fri Dec 22 12:56:40 2017 +0100
tdf#113877 Insert document: merge two list into one
When inserting a new document into current position we need to
concat to lists into one.
Added unit tests.
Change-Id: I10689256e0ffc5cf93722b1d45f09f610211b14a
Reviewed-on: https://gerrit.libreoffice.org/46991
Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
Tested-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
diff --git a/sw/qa/extras/uiwriter/data/tdf113877_insert_numbered_list.odt b/sw/qa/extras/uiwriter/data/tdf113877_insert_numbered_list.odt
new file mode 100755
index 000000000000..db480edbebaf
Binary files /dev/null and b/sw/qa/extras/uiwriter/data/tdf113877_insert_numbered_list.odt differ
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index afdd8aee20dc..39190dffc906 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -207,6 +207,7 @@ public:
void testTdf105417();
void testTdf112025();
void testTdf114306();
+ void testTdf113877();
CPPUNIT_TEST_SUITE(SwUiWriterTest);
CPPUNIT_TEST(testReplaceForward);
@@ -313,6 +314,7 @@ public:
CPPUNIT_TEST(testTdf105417);
CPPUNIT_TEST(testTdf112025);
CPPUNIT_TEST(testTdf114306);
+ CPPUNIT_TEST(testTdf113877);
CPPUNIT_TEST_SUITE_END();
private:
@@ -3812,6 +3814,32 @@ void SwUiWriterTest::testTdf114306()
xmlXPathFreeObject(pXmlObj);
}
+void SwUiWriterTest::testTdf113877()
+{
+ load(DATA_DIRECTORY, "tdf113877_insert_numbered_list.odt");
+
+ // set a page cursor into the end of the document
+ uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
+ uno::Reference<text::XTextViewCursorSupplier> xTextViewCursorSupplier(xModel->getCurrentController(), uno::UNO_QUERY);
+ uno::Reference<text::XPageCursor> xCursor(xTextViewCursorSupplier->getViewCursor(), uno::UNO_QUERY);
+ xCursor->jumpToEndOfPage();
+
+ // insert the same document at current cursor position
+ {
+ const OUString insertFileid = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf113877_insert_numbered_list.odt";
+ uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence({ { "Name", uno::makeAny(insertFileid) } }));
+ lcl_dispatchCommand(mxComponent, ".uno:InsertDoc", aPropertyValues);
+ }
+
+ // the initial list with 4 list items
+ CPPUNIT_ASSERT_EQUAL(getProperty<OUString>(getParagraph(1), "ListId"), getProperty<OUString>(getParagraph(4), "ListId"));
+
+ // the last of the first list, and the first of the inserted list
+ CPPUNIT_ASSERT_EQUAL(getProperty<OUString>(getParagraph(4), "ListId"), getProperty<OUString>(getParagraph(5), "ListId"));
+ CPPUNIT_ASSERT_EQUAL(getProperty<OUString>(getParagraph(5), "ListId"), getProperty<OUString>(getParagraph(6), "ListId"));
+ CPPUNIT_ASSERT_EQUAL(getProperty<OUString>(getParagraph(6), "ListId"), getProperty<OUString>(getParagraph(7), "ListId"));
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/xml/xmlimp.cxx b/sw/source/filter/xml/xmlimp.cxx
index 8ee58ceb6bfc..824d9aa6b488 100644
--- a/sw/source/filter/xml/xmlimp.cxx
+++ b/sw/source/filter/xml/xmlimp.cxx
@@ -843,6 +843,91 @@ void SwXMLImport::endDocument()
pPaM->Move( fnMoveBackward );
}
}
+
+ // tdf#113877
+ // when we insert one document with list inside into another one with list at the insert position,
+ // the resulting numbering in these lists are not consequent.
+ //
+ // Main document:
+ // 1. One
+ // 2. Two
+ // 3. Three
+ // 4. <-- insert position
+ //
+ // Inserted document:
+ // 1. One
+ // 2. Two
+ // 3. Three
+ // 4.
+ //
+ // Expected result
+ // 1. One
+ // 2. Two
+ // 3. Three
+ // 4. One
+ // 5. Two
+ // 6. Three
+ // 7.
+ //
+ if (IsInsertMode() && m_pSttNdIdx->GetIndex())
+ {
+ sal_uLong index = 1;
+
+ // the last node of the main document where we have inserted a document
+ SwNode * p1 = pDoc->GetNodes()[m_pSttNdIdx->GetIndex() + 0];
+
+ // the first node of the inserted document
+ SwNode * p2 = pDoc->GetNodes()[m_pSttNdIdx->GetIndex() + index];
+
+ // the first node of the inserted document,
+ // which will be used to detect if inside inserted document a new list was started
+ const SfxPoolItem* listId2Initial = nullptr;
+
+ while (
+ p1 && p2
+ && (p1->GetNodeType() == p2->GetNodeType())
+ && (p1->IsTextNode() == p2->IsTextNode())
+ )
+ {
+ SwContentNode * c1 = static_cast<SwContentNode *>(p1);
+ SwContentNode * c2 = static_cast<SwContentNode *>(p2);
+
+ const SfxPoolItem* listId1 = c1->GetNoCondAttr(RES_PARATR_LIST_ID, false);
+ const SfxPoolItem* listId2 = c2->GetNoCondAttr(RES_PARATR_LIST_ID, false);
+
+ if (!listId2Initial)
+ {
+ listId2Initial = listId2;
+ }
+
+ if (! (listId2Initial && listId2 && (*listId2Initial == *listId2)) )
+ {
+ // no more list items of the first list inside inserted document
+ break;
+ }
+
+ if (listId1 && listId2)
+ {
+ c2->SetAttr(*listId1);
+ }
+ else
+ {
+ // no more appropriate list items
+ break;
+ }
+
+ // get next item
+ index++;
+ if (index >= pDoc->GetNodes().Count())
+ {
+ // no more items
+ break;
+ }
+
+ p2 = pDoc->GetNodes()[m_pSttNdIdx->GetIndex() + index];
+ }
+ }
+
}
}
More information about the Libreoffice-commits
mailing list