From 26767050da42a79916b386aec76314b1da196dcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Wed, 29 Apr 2020 09:45:43 +0200 Subject: [PATCH] Create the proper shortcode on paste (#21864) --- .../src/components/rich-text/index.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/block-editor/src/components/rich-text/index.js b/packages/block-editor/src/components/rich-text/index.js index 7d95d8ce5c396f..2d73bed67d5c8c 100644 --- a/packages/block-editor/src/components/rich-text/index.js +++ b/packages/block-editor/src/components/rich-text/index.js @@ -39,6 +39,7 @@ import { } from '@wordpress/rich-text'; import deprecated from '@wordpress/deprecated'; import { isURL } from '@wordpress/url'; +import { regexp } from '@wordpress/shortcode'; /** * Internal dependencies @@ -93,6 +94,8 @@ function getAllowedFormats( { getAllowedFormats.EMPTY_ARRAY = []; +const isShortcode = ( text ) => regexp( '.*' ).test( text ); + function RichTextWrapper( { children, @@ -400,6 +403,18 @@ function RichTextWrapper( let mode = onReplace && onSplit ? 'AUTO' : 'INLINE'; + // Force the blocks mode when the user is pasting + // on a new line & the content resembles a shortcode. + // Otherwise it's going to be detected as inline + // and the shortcode won't be replaced. + if ( + mode === 'AUTO' && + isEmpty( value ) && + isShortcode( plainText ) + ) { + mode = 'BLOCKS'; + } + if ( __unstableEmbedURLOnPaste && isEmpty( value ) &&