Change paste special behaviour for markdown

To mimic plain text paste behaviour for markdown as it is just
plain text with some additional formatting elements.

Changed the type of DataFlavor from cppu::UnoType<Sequence<sal_Int8>>::get() to
cppu::UnoType<OUString>::get() and the corresponding handling in sw/source/uibase/dochdl/swdtflvr.cxx
which allows us to use the same conditions for markdown as text/plaintext with utf16 encoding as
the mimetype for markdown is not detected on most of the system.

1. https://gerrit.libreoffice.org/c/core/+/187792: Initial commit which added markdown
   into the clipboard registry with DataFlavor type as cppu::UnoType<Sequence<sal_Int8>>::get()

2. https://gerrit.libreoffice.org/c/core/+/188067: This patch introduced a new dialog
   which added the feature to select between plain text and markdown when using paste special -> unformatted text.

After the previous patch the design team suggested to remove the dialog.

3. https://gerrit.libreoffice.org/c/core/+/191225: Removed the dialog and added heuristic
   detection of markdown when pasting as plain text.

Backtracking to point 2: Mike Kaganski suggested to add markdown under paste special explicitly
removing the need of heuristic detection.

This is a followup patch for the previous suggestion.

----cherry pick note----
master and distro/collabora/co-25.04, distro/collabora/co-26.04
branches diverged while cherry-picking I423bfa356c337e7a6365beda0dcf1fff233f3edd
on 25.04 branch due to code review suggestions which introduced
an additional patch I44ffb00e240425701c4677bb58667141658845a5(this change)
being merged on distro/collabora branches.

This patch is to sync the changes between master and disto/collabora
branches.

Change-Id: I44ffb00e240425701c4677bb58667141658845a5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199975
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/201493
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/202306
Tested-by: Jenkins
This commit is contained in:
Ujjawal Kumar
2026-03-24 09:43:39 +01:00
committed by Mike Kaganski
parent 8dd5c09b19
commit c75975d1ac
+24 -33
View File
@@ -2211,50 +2211,42 @@ bool SwTransferable::PasteFileContent( const TransferableDataHelper& rData,
Reader* pRead = nullptr;
OUString sData;
bool bSkipInvalidateNumRules = false;
switch( nFormat )
bool bCheckStream = true;
if (nFormat == SotClipboardFormatId::STRING || nFormat == SotClipboardFormatId::MARKDOWN)
{
case SotClipboardFormatId::STRING:
if( rData.GetString( nFormat, sData ) )
{
pRead = ReadAscii;
bCheckStream = false;
pStream = new SvMemoryStream( const_cast<sal_Unicode *>(sData.getStr()),
sData.getLength() * sizeof( sal_Unicode ),
StreamMode::READ );
pStream->ResetEndianSwap();
const SwPosition& rInsertPosition = *rSh.GetCursor()->Start();
if (CanSkipInvalidateNumRules(rInsertPosition))
if (nFormat == SotClipboardFormatId::STRING)
{
// Insertion point is not a numbering and we paste plain text: then no need to
// invalidate all numberings.
bSkipInvalidateNumRules = true;
}
if( rData.GetString( nFormat, sData ) )
{
pStream = new SvMemoryStream( const_cast<sal_Unicode *>(sData.getStr()),
sData.getLength() * sizeof( sal_Unicode ),
StreamMode::READ );
pStream->ResetEndianSwap();
const SwPosition& rInsertPosition = *rSh.GetCursor()->Start();
if (CanSkipInvalidateNumRules(rInsertPosition))
{
// Insertion point is not a numbering and we paste plain text: then no need to
// invalidate all numberings.
bSkipInvalidateNumRules = true;
}
pRead = ReadAscii;
SwAsciiOptions aAOpt;
aAOpt.SetCharSet( RTL_TEXTENCODING_UCS2 );
pRead->GetReaderOpt().SetASCIIOpts( aAOpt );
break;
}
}
[[fallthrough]]; // because then test if we get a stream
case SotClipboardFormatId::MARKDOWN:
{
pRead = ReadMarkdown;
if( rData.GetString( nFormat, sData ) )
else
{
pStream = new SvMemoryStream( const_cast<sal_Unicode *>(sData.getStr()),
sData.getLength() * sizeof( sal_Unicode ),
StreamMode::READ );
pStream->ResetEndianSwap();
break;
pRead = ReadMarkdown;
}
}
[[fallthrough]];
}
default:
if (bCheckStream)
{
if( (xStrm = rData.GetSotStorageStream( nFormat )) )
{
if( ( SotClipboardFormatId::HTML_SIMPLE == nFormat ) ||
@@ -2273,14 +2265,13 @@ bool SwTransferable::PasteFileContent( const TransferableDataHelper& rData,
pStream = xStrm.get();
if( SotClipboardFormatId::RTF == nFormat || SotClipboardFormatId::RICHTEXT == nFormat)
pRead = SwReaderWriter::GetRtfReader();
else if( !pRead )
else
{
pRead = ReadHTML;
pRead->SetReadUTF8( true );
}
}
}
break;
}
TranslateId pResId;