From 30da76050c60acca4e1a03d01d6142f9bfd6d2a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ella=20van=C2=A0Durpe?= Date: Fri, 24 Feb 2023 15:38:09 +0200 Subject: [PATCH] Fix inline paste --- .../src/components/rich-text/use-paste-handler.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/rich-text/use-paste-handler.js b/packages/block-editor/src/components/rich-text/use-paste-handler.js index 66d1aab7061bf..83716b1669387 100644 --- a/packages/block-editor/src/components/rich-text/use-paste-handler.js +++ b/packages/block-editor/src/components/rich-text/use-paste-handler.js @@ -9,6 +9,8 @@ import { findTransform, getBlockTransforms, htmlToBlocks, + hasBlockSupport, + getBlockInnerHTML, } from '@wordpress/blocks'; import { isEmpty, @@ -45,6 +47,15 @@ function adjustLines( value, isMultiline ) { return replace( value, new RegExp( LINE_SEPARATOR, 'g' ), '\n' ); } +function maybeInline( blocks, mode ) { + if ( mode !== 'AUTO' ) return blocks; + if ( blocks.length !== 1 ) return blocks; + const [ block ] = blocks; + if ( ! hasBlockSupport( block.name, '__unstablePasteTextInline', false ) ) + return blocks; + return getBlockInnerHTML( block ); +} + export function usePasteHandler( props ) { const propsRef = useRef( props ); propsRef.current = props; @@ -215,7 +226,7 @@ export function usePasteHandler( props ) { // pasted content and remove inline styles. const isInternal = !! clipboardData.getData( 'rich-text' ); const content = isInternal - ? htmlToBlocks( html ) + ? maybeInline( htmlToBlocks( html ), mode ) : pasteHandler( { HTML: html, plainText,