summaryrefslogtreecommitdiff
path: root/sw/source
diff options
context:
space:
mode:
authorSerge Krot <Serge.Krot@cib.de>2017-12-22 12:56:40 +0100
committerThorsten Behrens <Thorsten.Behrens@CIB.de>2017-12-28 01:41:05 +0100
commit864ab0502a4d3506413451e8c545144c6c15d777 (patch)
treefb66429a78358f8c5f448b5d8a3363af32350044 /sw/source
parent88f6ffeb9e0c0b942c2b0bc9d60af7bb7a6caaf8 (diff)
tdf#113877 Insert document: merge two lists into one
When inserting a new document into current position we need to concat to lists into one. Added unit test. Change-Id: I10689256e0ffc5cf93722b1d45f09f610211b14a Reviewed-on: https://gerrit.libreoffice.org/46978 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Diffstat (limited to 'sw/source')
-rw-r--r--sw/source/filter/xml/xmlimp.cxx85
1 files changed, 85 insertions, 0 deletions
diff --git a/sw/source/filter/xml/xmlimp.cxx b/sw/source/filter/xml/xmlimp.cxx
index 80350796f3cf..29d4a6e64c7b 100644
--- a/sw/source/filter/xml/xmlimp.cxx
+++ b/sw/source/filter/xml/xmlimp.cxx
@@ -826,6 +826,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];
+ }
+ }
+
}
}