Skip to content

Commit

Permalink
Rich text: Honour embed-URL-on-paste setting for internal values too
Browse files Browse the repository at this point in the history
Fixes #57487
  • Loading branch information
mcsf committed Feb 7, 2024
1 parent eeffb21 commit 707583b
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions packages/block-editor/src/components/rich-text/use-paste-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,18 @@ export function usePasteHandler( props ) {
const isInternal =
event.clipboardData.getData( 'rich-text' ) === 'true';

const trimmedPlainText = plainText.trim();

const isPasteableUrl =
__unstableEmbedURLOnPaste &&
isURL( trimmedPlainText ) &&
// For the link pasting feature, allow only http(s) protocols.
/^https?:/.test( trimmedPlainText );

// If the data comes from a rich text instance, we can directly use it
// without filtering the data. The filters are only meant for externally
// pasted content and remove inline styles.
if ( isInternal ) {
if ( isInternal && ! isPasteableUrl ) {
const pastedValue = create( { html } );
addActiveFormats( pastedValue, value.activeFormats );
onChange( insert( value, pastedValue ) );
Expand Down Expand Up @@ -115,15 +123,7 @@ export function usePasteHandler( props ) {

let mode = onReplace && onSplit ? 'AUTO' : 'INLINE';

const trimmedPlainText = plainText.trim();

if (
__unstableEmbedURLOnPaste &&
isEmpty( value ) &&
isURL( trimmedPlainText ) &&
// For the link pasting feature, allow only http(s) protocols.
/^https?:/.test( trimmedPlainText )
) {
if ( isPasteableUrl && isEmpty( value ) ) {
mode = 'BLOCKS';
}

Expand Down

0 comments on commit 707583b

Please sign in to comment.