diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2020-06-22 21:04:47 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2020-06-23 09:02:21 +0200 |
commit | e0d0274c2b806f5148b413926ec2e58c75ce04a1 (patch) | |
tree | 1c85d0372eabba28a4b883bfda08418c7ae9fb7d /sw/qa | |
parent | 28f3d9c23bc269cf4c49a4f1f282b0cd27e66fef (diff) |
tdf#119081 sw: fix RTF paste into outer table cell
Regression from commit ed654c4aa7f9f10fcb16127349009bc0c38b12e8 (Revert
"fdo#43869 use the old rtf importer for paste", 2012-11-30), the direct
problem is that SwXText::insertTextPortion() is now used by
writerfilter, so in case it's not as good as the internal API used by
the old RTF filter, we have a problem.
This function calls SwXCell::CreateCursor(), which calls
SwXCell::createTextCursor(), which uses Move() to go to the first
content node in the cell, but that means we end up at the inner cell's
XText for an outer cell.
So later when we want to go to the end of the outer cell, we can't, as
that would be a different XText and we throw an exception.
Fix the problem by instead using createTextCursorByRange(), which
immediately positions the cursor at the insert position, so the XText
will be correct.
FWIW, the ODF import at SwXMLImport::setTextInsertMode() also uses
createTextCursorByRange() to handle this situation.
Change-Id: I1db13b860bc60771d98c2b4099be73f4bf41c375
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96901
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sw/qa')
-rw-r--r-- | sw/qa/core/unocore/data/tdf119081.odt | bin | 0 -> 9000 bytes | |||
-rw-r--r-- | sw/qa/core/unocore/unocore.cxx | 91 |
2 files changed, 91 insertions, 0 deletions
diff --git a/sw/qa/core/unocore/data/tdf119081.odt b/sw/qa/core/unocore/data/tdf119081.odt Binary files differnew file mode 100644 index 000000000000..a9b479dd59df --- /dev/null +++ b/sw/qa/core/unocore/data/tdf119081.odt diff --git a/sw/qa/core/unocore/unocore.cxx b/sw/qa/core/unocore/unocore.cxx new file mode 100644 index 000000000000..d8d72ecf369f --- /dev/null +++ b/sw/qa/core/unocore/unocore.cxx @@ -0,0 +1,91 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <swmodeltestbase.hxx> + +#include <com/sun/star/awt/FontSlant.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/text/TextContentAnchorType.hpp> +#include <com/sun/star/text/AutoTextContainer.hpp> +#include <com/sun/star/text/VertOrientation.hpp> +#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/text/XTextAppend.hpp> +#include <com/sun/star/rdf/URI.hpp> +#include <com/sun/star/rdf/URIs.hpp> +#include <com/sun/star/awt/XDevice.hpp> +#include <com/sun/star/awt/XToolkit.hpp> +#include <com/sun/star/graphic/XGraphic.hpp> +#include <com/sun/star/style/LineSpacing.hpp> +#include <com/sun/star/view/XSelectionSupplier.hpp> + +#include <comphelper/propertyvalue.hxx> +#include <toolkit/helper/vclunohelper.hxx> +#include <vcl/graphicfilter.hxx> + +#include <wrtsh.hxx> +#include <ndtxt.hxx> +#include <swdtflvr.hxx> +#include <view.hxx> +#include <PostItMgr.hxx> +#include <postithelper.hxx> +#include <AnnotationWin.hxx> +#include <flyfrm.hxx> +#include <fmtanchr.hxx> +#include <unotextrange.hxx> + +using namespace ::com::sun::star; + +namespace +{ +char const DATA_DIRECTORY[] = "/sw/qa/core/unocore/data/"; +} + +/// Covers sw/source/core/unocore/ fixes. +class SwCoreUnocoreTest : public SwModelTestBase +{ +}; + +CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, testTdf119081) +{ + // Load a doc with a nested table in it. + load(DATA_DIRECTORY, "tdf119081.odt"); + SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + SwDocShell* pDocShell = pTextDoc->GetDocShell(); + SwWrtShell* pWrtShell = pDocShell->GetWrtShell(); + + // Enter outer A1. + pWrtShell->Down(/*bSelect=*/false, /*nCount=*/3); + // Enter inner A1. + pWrtShell->Right(CRSR_SKIP_CELLS, /*bSelect=*/false, /*nCount=*/1, /*bBasicCall=*/false, + /*bVisual=*/true); + // Enter outer B1. + pWrtShell->Down(/*bSelect=*/false, /*nCount=*/2); + + SwDoc* pDoc = pDocShell->GetDoc(); + SwPaM& rCursor = pWrtShell->GetCurrentShellCursor(); + uno::Reference<text::XTextRange> xInsertPosition + = SwXTextRange::CreateXTextRange(*pDoc, *rCursor.GetPoint(), nullptr); + uno::Reference<text::XTextAppend> xTextAppend(xInsertPosition->getText(), uno::UNO_QUERY); + // Without the accompanying fix in place, this test would have failed with: + // An uncaught exception of type com.sun.star.uno.RuntimeException + xTextAppend->insertTextPortion("x", {}, xInsertPosition); + + // Verify that the string is indeed inserted. + pWrtShell->Left(CRSR_SKIP_CELLS, /*bSelect=*/true, /*nCount=*/1, /*bBasicCall=*/false, + /*bVisual=*/true); + CPPUNIT_ASSERT_EQUAL(OUString("x"), pWrtShell->GetCurrentShellCursor().GetText()); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |