Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rich text: Honour embed-URL-on-paste setting for internal values too #58786

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works, but I would much rather make the logic below that handles __unstablePasteRule transforms reusable and run it here as well, instead of making an exception for URLs and letting that from through the paste handler for nothing. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ellatrix: Fine by me! This was just a quick stab, but I'll happily defer to a more comprehensive solution of your making.

Copy link
Member

@ellatrix ellatrix Feb 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's what I meant: #59063

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