[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. <a href="#">te[]st</a>
	+ pasting <h1>123</h1>  <=>
	<a href="#">te<h1>123</h1>st</a>

Desired behaviour after commit:

-Now only text content is pasted which makes
pasted content as a part of the link.

e.g. <a href="#">te[]st</a>
	+ pasting <h1>123</h1>  <=>
	<a href="#">te123st</a>

closes odoo/odoo#134516

X-original-commit: 1cc3354b88658620c15fa18427b8725b6215337d
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
This commit is contained in:
Adnan Saiyed
2023-09-06 14:42:20 +00:00
parent f4ee483fde
commit 84276cbd63
2 changed files with 15 additions and 1 deletions
@@ -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');
@@ -1548,6 +1548,15 @@ describe('Paste', () => {
contentAfter: `<p><a href="${url}">${url}</a> abc <a href="${videoUrl}">${videoUrl}</a> def <a href="${imgUrl}">${imgUrl}</a>[]</p>`,
});
});
it('should paste plain text inside non empty link', async () => {
await testEditor(BasicEditor, {
contentBefore: '<p><a href="#">a[]b</a></p>',
stepFunction: async editor => {
await pasteHtml(editor, '<span>123</span>');
},
contentAfter: '<p><a href="#">a123[]b</a></p>',
});
});
});
describe('range not collapsed', async () => {
it('should paste and transform an URL in a p', async () => {