From 84276cbd6398a57aa489a70af5b61d050bccf541 Mon Sep 17 00:00:00 2001 From: Adnan Saiyed Date: Tue, 13 Jun 2023 13:26:01 +0000 Subject: [PATCH] [FIX] web_editor: unexpected copy paste behaviour of link Current behaviour before commit: -When pasting copied content from editor inside link inserts text with HTML content, in result the pasted content seems isolated from the link. e.g. te[]st + pasting

123

<=> te

123

st
Desired behaviour after commit: -Now only text content is pasted which makes pasted content as a part of the link. e.g. te[]st + pasting

123

<=> te123st closes odoo/odoo#134516 X-original-commit: 1cc3354b88658620c15fa18427b8725b6215337d Signed-off-by: David Monjoie (dmo) --- .../static/src/js/editor/odoo-editor/src/OdooEditor.js | 7 ++++++- .../js/editor/odoo-editor/test/spec/copyPaste.test.js | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js index 0098ded098c..48f7dcd6079 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js @@ -4638,7 +4638,12 @@ export class OdooEditor extends EventTarget { } }); } else { - this._applyCommand('insert', clipboardElem); + if (closestElement(sel.anchorNode, 'a')) { + this._applyCommand('insert', clipboardElem.textContent); + } + else { + this._applyCommand('insert', clipboardElem); + } } } else { const text = ev.clipboardData.getData('text/plain'); diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/copyPaste.test.js b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/copyPaste.test.js index 5d5a3c29727..b321bd5f132 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/copyPaste.test.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/copyPaste.test.js @@ -1548,6 +1548,15 @@ describe('Paste', () => { contentAfter: `

${url} abc ${videoUrl} def ${imgUrl}[]

`, }); }); + it('should paste plain text inside non empty link', async () => { + await testEditor(BasicEditor, { + contentBefore: '

a[]b

', + stepFunction: async editor => { + await pasteHtml(editor, '123'); + }, + contentAfter: '

a123[]b

', + }); + }); }); describe('range not collapsed', async () => { it('should paste and transform an URL in a p', async () => {