Skip to content

Commit 5538473

Browse files
fix(message-input): DP-131613 fix pasting links when no rich-text (#653)
1 parent 205f2b1 commit 5538473

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

packages/dialtone-vue2/components/rich_text_editor/rich_text_editor.stories.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,5 +155,6 @@ export const WithCustomExtensions = {
155155
allowUnderline: false,
156156
allowCode: false,
157157
allowCodeblock: false,
158+
link: false,
158159
},
159160
};

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,6 @@ export default {
655655
},
656656
657657
methods: {
658-
659658
createEditor () {
660659
// For all available options, see https://tiptap.dev/api/editor#settings
661660
this.editor = new Editor({
@@ -669,6 +668,17 @@ export default {
669668
class: this.inputClass,
670669
},
671670
671+
handlePaste: (_, event) => {
672+
// When having link and customLink props we should maintain default paste behavior
673+
if (!this.link && !this.customLink) {
674+
const pastedContent = event.clipboardData.getData('text');
675+
this.editor.chain().focus().insertContent(pastedContent).run();
676+
return true; // Prevent the default paste behavior
677+
}
678+
679+
return false; // Allow the default paste behavior
680+
},
681+
672682
// Moves the <br /> tags inside the previous closing tag to avoid
673683
// Prosemirror wrapping them within another </p> tag.
674684
transformPastedHTML (html) {

packages/dialtone-vue3/components/rich_text_editor/rich_text_editor.stories.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,5 +162,6 @@ export const WithCustomExtensions = {
162162
allowUnderline: false,
163163
allowCode: false,
164164
allowCodeblock: false,
165+
link: false,
165166
},
166167
};

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,17 @@ export default {
670670
class: this.inputClass,
671671
},
672672
673+
handlePaste: (_, event) => {
674+
// When having link and customLink props we should maintain default paste behavior
675+
if (!this.link && !this.customLink) {
676+
const pastedContent = event.clipboardData.getData('text');
677+
this.editor.chain().focus().insertContent(pastedContent).run();
678+
return true; // Prevent the default paste behavior
679+
}
680+
681+
return false; // Allow the default paste behavior
682+
},
683+
673684
// Moves the <br /> tags inside the previous closing tag to avoid
674685
// Prosemirror wrapping them within another </p> tag.
675686
transformPastedHTML (html) {

0 commit comments

Comments
 (0)