summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2017-11-14 17:39:41 +0100
committerEike Rathke <erack@redhat.com>2017-11-14 17:40:15 +0100
commit329eeefcbd65ea88f0c8c3f034d49ba73045d059 (patch)
tree05032ad9b703a1089c2a04a7ce68a8bb34cfd0f2
parented89b432dff252d3b1a18ad7694bbf2c4abc36ff (diff)
Distinguish single/multiple cell copy for plain text, tdf#113571 follow-up
A single cell may contain embedded line breaks and tabs, copy/pasting multiple cells may not. Change-Id: Iae58f5c6b5330b327acfb50a37e9d210e72de7c7
-rw-r--r--sc/source/ui/app/transobj.cxx23
1 files changed, 16 insertions, 7 deletions
diff --git a/sc/source/ui/app/transobj.cxx b/sc/source/ui/app/transobj.cxx
index a45583af79d7..e2e57ed657b6 100644
--- a/sc/source/ui/app/transobj.cxx
+++ b/sc/source/ui/app/transobj.cxx
@@ -320,18 +320,27 @@ bool ScTransferObj::GetData( const datatransfer::DataFlavor& rFlavor, const OUSt
}
ScImportExport aObj( pDoc, aReducedBlock );
- // Plain string ("Unformatted text") contains embedded line breaks
- // but is not enclosed in quotes. Which makes it unsuitable for
- // multiple cells if one of them is multi-line, but otherwise is
- // expected behavior for plain text.
+ // Plain text ("Unformatted text") may contain embedded tabs and
+ // line breaks but is not enclosed in quotes. Which makes it
+ // unsuitable for multiple cells, especially if one of them is
+ // multi-line, but otherwise is expected behavior for plain text.
+ // For multiple cells replace embedded line breaks (and tabs) with
+ // space character, otherwise pasting would yield odd results.
+ /* XXX: it's debatable whether this is actually expected, but
+ * there's no way to satisfy all possible requirements when
+ * copy/pasting unformatted text. */
+ const bool bPlainMulti = (nFormat == SotClipboardFormatId::STRING &&
+ aReducedBlock.aStart != aReducedBlock.aEnd);
// Add quotes only for STRING_TSVC.
/* TODO: a possible future STRING_TSV should not contain embedded
- * line breaks nor tab (separator) characters and not be quoted. */
+ * line breaks nor tab (separator) characters and not be quoted.
+ * A possible STRING_CSV should. */
ScExportTextOptions aTextOptions( ScExportTextOptions::None, 0,
(nFormat == SotClipboardFormatId::STRING_TSVC));
- if ( bUsedForLink )
+ if ( bPlainMulti || bUsedForLink )
{
- // For a DDE link, convert line breaks and separators to space.
+ // For a DDE link or plain text multiple cells, convert line
+ // breaks and separators to space.
aTextOptions.meNewlineConversion = ScExportTextOptions::ToSpace;
aTextOptions.mcSeparatorConvertTo = ' ';
aTextOptions.mbAddQuotes = false;