summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2020-01-10 16:03:43 +0100
committerMiklos Vajna <vmiklos@collabora.com>2020-01-10 17:20:23 +0100
commitc12358166a9bd88fe10feabca45a6ad3f65dff8e (patch)
treec1f99c98052fbbd8d8c063bf626b43a3115e860c /sw
parentcd260db2ac2e96455df5bae00dc371565f16255b (diff)
DOCX import: fix lost objects anchored to an empty linked header
This is really similar to commit 04b2310aaa094794ceedaa1bb6ff1823a2d29d3e (DOCX import: fix lost objects anchored to the single para of a linked header, 2020-01-10), except here the header is not just a single-paragraph one, but has no text portions. Update text-copy.docx to have a header which is not only a single paragraph, but also has no character content. This keeps testing the original case, but now also tests the more strict case (single paragraph -> single empty paragraph). Change-Id: I11bb062e77af1a83f717225ea5b4daef39e5a672 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86552 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/ooxmlimport/data/text-copy.docxbin16306 -> 16288 bytes
-rw-r--r--sw/qa/extras/ooxmlimport/ooxmlimport2.cxx1
-rw-r--r--sw/source/core/doc/DocumentContentOperationsManager.cxx19
3 files changed, 18 insertions, 2 deletions
diff --git a/sw/qa/extras/ooxmlimport/data/text-copy.docx b/sw/qa/extras/ooxmlimport/data/text-copy.docx
index 9c871e633517..03c0563b37fd 100644
--- a/sw/qa/extras/ooxmlimport/data/text-copy.docx
+++ b/sw/qa/extras/ooxmlimport/data/text-copy.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
index 11243d14e33d..d75a8c0dc4fe 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
@@ -287,6 +287,7 @@ DECLARE_OOXMLIMPORT_TEST(testTextCopy, "text-copy.docx")
{
// The document has a header on the second page that is copied as part of the import process.
// The header has a single paragraph: make sure shapes anchored to it are not lost.
+ // Note that the single paragraph itself has no text portions.
uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(),
uno::UNO_QUERY);
diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx b/sw/source/core/doc/DocumentContentOperationsManager.cxx
index 1d56e41dde50..0cc15a92e4d2 100644
--- a/sw/source/core/doc/DocumentContentOperationsManager.cxx
+++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx
@@ -1828,6 +1828,21 @@ DocumentContentOperationsManager::DocumentContentOperationsManager( SwDoc& i_rSw
{
}
+/**
+ * Checks if rStart..rEnd mark a range that makes sense to copy.
+ *
+ * bCopyText means that an empty range is OK, since paragraph-anchored objects may present.
+ */
+static bool IsEmptyRange(const SwPosition& rStart, const SwPosition& rEnd, bool bCopyText)
+{
+ bool bEmptyRange = rStart >= rEnd;
+ if (bCopyText)
+ {
+ bEmptyRange = rStart > rEnd;
+ }
+ return bEmptyRange;
+}
+
// Copy an area into this document or into another document
bool
DocumentContentOperationsManager::CopyRange( SwPaM& rPam, SwPosition& rPos, const bool bCopyAll, bool bCheckPos, bool bCopyText ) const
@@ -1838,7 +1853,7 @@ DocumentContentOperationsManager::CopyRange( SwPaM& rPam, SwPosition& rPos, cons
bool bColumnSel = pDoc->IsClipBoard() && pDoc->IsColumnSelection();
// Catch if there's no copy to do
- if( !rPam.HasMark() || ( *pStt >= *pEnd && !bColumnSel ) )
+ if (!rPam.HasMark() || (IsEmptyRange(*pStt, *pEnd, bCopyText) && !bColumnSel))
return false;
// Prevent copying in Flys that are anchored in the area
@@ -4526,7 +4541,7 @@ bool DocumentContentOperationsManager::CopyImplImpl(SwPaM& rPam, SwPosition& rPo
SwPosition *const pEnd = rPam.End();
// Catch when there's no copy to do.
- if( !rPam.HasMark() || ( *pStt >= *pEnd && !bColumnSel ) ||
+ if (!rPam.HasMark() || (IsEmptyRange(*pStt, *pEnd, bCopyText) && !bColumnSel) ||
//JP 29.6.2001: 88963 - don't copy if inspos is in region of start to end
//JP 15.11.2001: don't test inclusive the end, ever exclusive
( pDoc == &m_rDoc && *pStt <= rPos && rPos < *pEnd ))