Skip to content

Commit

Permalink
Fix inline paste
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Feb 24, 2023
1 parent 70bcc51 commit 30da760
Showing 1 changed file with 12 additions and 1 deletion.
Expand Up @@ -9,6 +9,8 @@ import {
findTransform,
getBlockTransforms,
htmlToBlocks,
hasBlockSupport,
getBlockInnerHTML,
} from '@wordpress/blocks';
import {
isEmpty,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 30da760

Please sign in to comment.