diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2020-04-22 16:25:51 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2020-04-22 20:08:20 +0200 |
commit | 8ad0c29f56e5069a3679560d404b603332dcf38a (patch) | |
tree | cb8c011fee039d8c27eb1de849071faa3fe02640 /sw/qa | |
parent | 688a520111a2dd3ab4cb3b846b561936d8a887bf (diff) |
sw: prefer ODF over RTF when pasting from Writer
Regression from commit e9e6d4b058e13165f3dde1ca7822eec97dfe8aa7
(tdf#116685: Make the RICHTEXT take precedence over EMBED_SOURCE.,
2019-09-26), the problem was that now we always prefer RTF over ODF when
pasting into Writer. The commit made sense for Calc->Writer paste, but
it causes formatting loss for Writer -> Writer paste.
The exact use-case was copy&paste of numberings where the pasted content
got paragraph indent as direct formatting, so shift-tab at the paragraph
start changed only the bullet type, not the indentation -- but it's easy
to imagine several other cases where a roundtrip via ODF provides better
results than RTF.
Fix the problem by leaving the above commit in place, but extending
SwTransferable::Paste() so that it prefers ODF over RTF in case of a
Writer->Writer paste (and leaves the non-Writer -> Writer paste behavior
unchanged to avoid the unwanted OLE objects).
Change-Id: Ida745bba65c5a210021cea0d267c02900fc6398a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92705
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sw/qa')
-rw-r--r-- | sw/qa/uibase/dochdl/dochdl.cxx | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/sw/qa/uibase/dochdl/dochdl.cxx b/sw/qa/uibase/dochdl/dochdl.cxx new file mode 100644 index 000000000000..07e50a78df36 --- /dev/null +++ b/sw/qa/uibase/dochdl/dochdl.cxx @@ -0,0 +1,75 @@ +/* -*- 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 <sfx2/dispatch.hxx> +#include <sfx2/viewfrm.hxx> +#include <vcl/GraphicObject.hxx> +#include <svx/svdpage.hxx> +#include <editeng/eeitem.hxx> +#include <editeng/adjustitem.hxx> +#include <editeng/outlobj.hxx> +#include <editeng/editobj.hxx> +#include <vcl/transfer.hxx> + +#include <IDocumentContentOperations.hxx> +#include <cmdid.h> +#include <fmtanchr.hxx> +#include <view.hxx> +#include <wrtsh.hxx> +#include <IDocumentDrawModelAccess.hxx> +#include <drawdoc.hxx> +#include <swdtflvr.hxx> + +/// Covers sw/source/uibase/dochdl/ fixes. +class SwUibaseDochdlTest : public SwModelTestBase +{ +public: + SwDoc* createDoc(); +}; + +SwDoc* SwUibaseDochdlTest::createDoc() +{ + loadURL("private:factory/swriter", nullptr); + + SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + return pTextDoc->GetDocShell()->GetDoc(); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseDochdlTest, testSelectPasteFormat) +{ + // Create a new document and cut a character. + SwDoc* pDoc = createDoc(); + SwDocShell* pDocShell = pDoc->GetDocShell(); + SwWrtShell* pWrtShell = pDocShell->GetWrtShell(); + pWrtShell->Insert2("x"); + pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/true, 1, /*bBasicCall=*/false); + rtl::Reference<SwTransferable> pTransfer = new SwTransferable(*pWrtShell); + pTransfer->Cut(); + + // Decide what format to use when doing a Writer->Writer paste and both RTF and ODF is an + // available format. + TransferableDataHelper aHelper(pTransfer.get()); + sal_uInt8 nAction = EXCHG_OUT_ACTION_INSERT_STRING; + SotClipboardFormatId nFormat = SotClipboardFormatId::RICHTEXT; + SwTransferable::SelectPasteFormat(aHelper, nAction, nFormat); + + CPPUNIT_ASSERT_EQUAL(EXCHG_OUT_ACTION_INSERT_OLE, nAction); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 85 (EMBED_SOURCE) + // - Actual : 145 (RICHTEXT) + // i.e. RTF was selected for Writer->Writer out of process copying, which is worse than ODF. + CPPUNIT_ASSERT_EQUAL(SotClipboardFormatId::EMBED_SOURCE, nFormat); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |