sot/source/base/exchange.cxx | 2 - sw/source/uibase/dochdl/swdtflvr.cxx | 53 +++++++++++++++++------------------ 2 files changed, 28 insertions(+), 27 deletions(-)
New commits: commit f5f93f6e30159b67235099f19e3a34f03228e88d Author: Ujjawal Kumar <[email protected]> AuthorDate: Sun Feb 22 16:33:01 2026 +0530 Commit: Michael Stahl <[email protected]> CommitDate: Wed Feb 25 14:02:03 2026 +0100 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. Change-Id: I44ffb00e240425701c4677bb58667141658845a5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199975 Reviewed-by: Mike Kaganski <[email protected]> Tested-by: Jenkins CollaboraOffice <[email protected]> diff --git a/sot/source/base/exchange.cxx b/sot/source/base/exchange.cxx index 3e9855162e22..b21a31848839 100644 --- a/sot/source/base/exchange.cxx +++ b/sot/source/base/exchange.cxx @@ -202,7 +202,7 @@ const DataFlavorRepresentation* FormatArray_Impl() /*146 SotClipboardFormatId::STRING_TSVC*/ { u"application/x-libreoffice-tsvc"_ustr, "Text TSV-Calc", &cppu::UnoType<OUString>::get() }, /*147 SotClipboardFormatId::PDF*/ { u"application/pdf"_ustr, "PDF Document", &cppu::UnoType<Sequence<sal_Int8>>::get() }, /*148 SotClipboardFormatId::SVG*/ { u"image/svg+xml;windows_formatname=\"image/svg+xml\""_ustr, "SVG", &cppu::UnoType<Sequence<sal_Int8>>::get() }, - /*149 SotClipboardFormatId::MARKDOWN*/ { u"text/markdown"_ustr, "Markdown", &cppu::UnoType<Sequence<sal_Int8>>::get() }, + /*149 SotClipboardFormatId::MARKDOWN*/ { u"text/markdown"_ustr, "Markdown", &cppu::UnoType<OUString>::get() }, }; return &aInstance[0]; }; diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx b/sw/source/uibase/dochdl/swdtflvr.cxx index fda33f444ec7..952030882f95 100644 --- a/sw/source/uibase/dochdl/swdtflvr.cxx +++ b/sw/source/uibase/dochdl/swdtflvr.cxx @@ -2190,40 +2190,46 @@ 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; - - 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; - } - - if( rData.GetString( nFormat, sData ) ) - { - pStream = new SvMemoryStream( const_cast<sal_Unicode *>(sData.getStr()), + bCheckStream = false; + pStream = new SvMemoryStream( const_cast<sal_Unicode *>(sData.getStr()), sData.getLength() * sizeof( sal_Unicode ), StreamMode::READ ); #ifdef OSL_BIGENDIAN - pStream->SetEndian( SvStreamEndian::BIG ); + pStream->SetEndian( SvStreamEndian::BIG ); #else - pStream->SetEndian( SvStreamEndian::LITTLE ); + pStream->SetEndian( SvStreamEndian::LITTLE ); #endif + if (nFormat == SotClipboardFormatId::STRING) + { + 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; + } + else + { + pRead = ReadMarkdown; } } - [[fallthrough]]; // because then test if we get a stream + } - default: + if (bCheckStream) + { if( (xStrm = rData.GetSotStorageStream( nFormat )) ) { if( ( SotClipboardFormatId::HTML_SIMPLE == nFormat ) || @@ -2242,18 +2248,13 @@ bool SwTransferable::PasteFileContent( const TransferableDataHelper& rData, pStream = xStrm.get(); if( SotClipboardFormatId::RTF == nFormat || SotClipboardFormatId::RICHTEXT == nFormat) pRead = SwReaderWriter::GetRtfReader(); - else if( SotClipboardFormatId::MARKDOWN == nFormat ) - { - pRead = ReadMarkdown; - } - else if( !pRead ) + else { pRead = ReadHTML; pRead->SetReadUTF8( true ); } } } - break; } if( pStream && pRead )
