Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,25 @@ export default {
handlePaste: (_, event) => {
// When having link and customLink props we should maintain default paste behavior
if (!this.link && !this.customLink) {
const regex = /^https?:\/\//;
Comment thread
braddialpad marked this conversation as resolved.

if (!event?.clipboardData) {
return false;
}
const pastedContent = event.clipboardData.getData('text');

// Check if the pasted content is a valid URL (starting with http:// or https://)
// If it's not a URL, allow the default paste behavior
if (!regex.test(pastedContent)) {
return false;
}

// If `text/html` is missing from clipboard data, it's a plain link
// In this case, allow the default paste behavior
if (!event.clipboardData.getData('text/html')) {
return false;
}

Comment on lines +674 to +692
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm actually wondering if we should just ALWAYS take the text property from clipboard when our input is running in non-rich-text mode. Anyways that's a bit more dangerous so we can do this first.

this.editor.chain().focus().insertContent(pastedContent).run();
return true; // Prevent the default paste behavior
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,25 @@ export default {
handlePaste: (_, event) => {
// When having link and customLink props we should maintain default paste behavior
if (!this.link && !this.customLink) {
const regex = /^https?:\/\//;

if (!event?.clipboardData) {
return false;
}
const pastedContent = event.clipboardData.getData('text');

// Check if the pasted content is a valid URL (starting with http:// or https://)
// If it's not a URL, allow the default paste behavior
if (!regex.test(pastedContent)) {
return false;
}

// If `text/html` is missing from clipboard data, it's a plain link
// In this case, allow the default paste behavior
if (!event.clipboardData.getData('text/html')) {
return false;
}

this.editor.chain().focus().insertContent(pastedContent).run();
return true; // Prevent the default paste behavior
}
Expand Down
Loading