Skip to content

Commit d46fe42

Browse files
fix(rich-text-editor): DP-134543 patchfix paste (#676)
1 parent ddcda03 commit d46fe42

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

packages/dialtone-vue2/components/rich_text_editor/rich_text_editor.vue

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,25 @@ export default {
671671
handlePaste: (_, event) => {
672672
// When having link and customLink props we should maintain default paste behavior
673673
if (!this.link && !this.customLink) {
674+
const regex = /^https?:\/\//;
675+
676+
if (!event?.clipboardData) {
677+
return false;
678+
}
674679
const pastedContent = event.clipboardData.getData('text');
680+
681+
// Check if the pasted content is a valid URL (starting with http:// or https://)
682+
// If it's not a URL, allow the default paste behavior
683+
if (!regex.test(pastedContent)) {
684+
return false;
685+
}
686+
687+
// If `text/html` is missing from clipboard data, it's a plain link
688+
// In this case, allow the default paste behavior
689+
if (!event.clipboardData.getData('text/html')) {
690+
return false;
691+
}
692+
675693
this.editor.chain().focus().insertContent(pastedContent).run();
676694
return true; // Prevent the default paste behavior
677695
}

packages/dialtone-vue3/components/rich_text_editor/rich_text_editor.vue

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,25 @@ export default {
673673
handlePaste: (_, event) => {
674674
// When having link and customLink props we should maintain default paste behavior
675675
if (!this.link && !this.customLink) {
676+
const regex = /^https?:\/\//;
677+
678+
if (!event?.clipboardData) {
679+
return false;
680+
}
676681
const pastedContent = event.clipboardData.getData('text');
682+
683+
// Check if the pasted content is a valid URL (starting with http:// or https://)
684+
// If it's not a URL, allow the default paste behavior
685+
if (!regex.test(pastedContent)) {
686+
return false;
687+
}
688+
689+
// If `text/html` is missing from clipboard data, it's a plain link
690+
// In this case, allow the default paste behavior
691+
if (!event.clipboardData.getData('text/html')) {
692+
return false;
693+
}
694+
677695
this.editor.chain().focus().insertContent(pastedContent).run();
678696
return true; // Prevent the default paste behavior
679697
}

0 commit comments

Comments
 (0)