sw/qa/extras/ooxmlimport/data/text-copy.docx |binary sw/qa/extras/ooxmlimport/ooxmlimport2.cxx | 1 sw/source/core/doc/DocumentContentOperationsManager.cxx | 19 ++++++++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-)
New commits: commit fec42b4fdd7e4fc57d30288e226ab4b238ac98a8 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Fri Jan 10 16:03:43 2020 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Tue Feb 4 13:34:40 2020 +0100 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 <vmik...@collabora.com> Tested-by: Jenkins (cherry picked from commit c12358166a9bd88fe10feabca45a6ad3f65dff8e) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87123 Reviewed-by: Michael Stahl <michael.st...@cib.de> (cherry picked from commit 8d58d0ef72162bbfb92cd3a894387f57c62ee8ae) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87856 Tested-by: Michael Stahl <michael.st...@cib.de> diff --git a/sw/qa/extras/ooxmlimport/data/text-copy.docx b/sw/qa/extras/ooxmlimport/data/text-copy.docx index 9c871e633517..03c0563b37fd 100644 Binary files a/sw/qa/extras/ooxmlimport/data/text-copy.docx and b/sw/qa/extras/ooxmlimport/data/text-copy.docx differ diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx index 8e62b2650c0f..bb9fbeea2860 100644 --- a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx +++ b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx @@ -255,6 +255,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 b60534a35374..0219ef38af0f 100644 --- a/sw/source/core/doc/DocumentContentOperationsManager.cxx +++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx @@ -1712,6 +1712,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 @@ -1722,7 +1737,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 @@ -4417,7 +4432,7 @@ bool DocumentContentOperationsManager::CopyImpl( SwPaM& rPam, SwPosition& rPos, 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 )) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits