Skip to content

Commit

Permalink
Create the proper shortcode on paste (#21864)
Browse files Browse the repository at this point in the history
  • Loading branch information
nosolosw authored Apr 29, 2020
1 parent ea4fa88 commit 2676705
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/block-editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -93,6 +94,8 @@ function getAllowedFormats( {

getAllowedFormats.EMPTY_ARRAY = [];

const isShortcode = ( text ) => regexp( '.*' ).test( text );

function RichTextWrapper(
{
children,
Expand Down Expand Up @@ -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 ) &&
Expand Down

0 comments on commit 2676705

Please sign in to comment.