[FIX] web_editor: do not paste a link if target does not support HTML
When pasting text inside the editor, if the text looks like a URL, a link is implicitly created. Unfortunately, this also happens when the edited element does not support HTML. Because of this, when translating a page, links are created inside the translated text which does not support HTML. This commit solves this by pasting the plain text if the target of the paste does not support HTML (which is the case for translations). This commit also prevent link creation when typing a space after text that looks like an URL in targets that do not support HTML. In saas-16.4, `_handleAutomaticLinkInsertion` is also adapted to prevent unwanted link creation. Steps to reproduce for first scenario: - Add French to your website. - Edit your master English Home page. - Drop a Text snippet in the Home page. - Save the Home page. - Switch to French. - Translate the page. - From an external text input, copy `http://odoo.com` in your clipboard. - Put the cursor inside the Text snippet's text. - Paste. => A link was created. Steps to reproduce for second scenario: - Add French to your website. - Edit your master English Home page. - Drop a Text snippet in the Home page. - Save the Home page. - Switch to French. - Translate the page. - Put the cursor inside the Text snippet's text. - Type `http://odoo.com` followed by a space. => A link was created. opw-3546308 closes odoo/odoo#150189 X-original-commit: de351e500559166963fd2e748229d5c1d901aa44 Signed-off-by: Benjamin Vray (bvr) <bvr@odoo.com>
This commit is contained in:
@@ -4700,6 +4700,7 @@ export class OdooEditor extends EventTarget {
|
||||
if (
|
||||
selection &&
|
||||
selection.anchorNode &&
|
||||
isHtmlContentSupported(selection.anchorNode) &&
|
||||
!closestElement(selection.anchorNode).closest('a') &&
|
||||
selection.anchorNode.nodeType === Node.TEXT_NODE
|
||||
) {
|
||||
@@ -4784,7 +4785,10 @@ export class OdooEditor extends EventTarget {
|
||||
link.remove();
|
||||
setSelection(...start, ...start, false);
|
||||
}
|
||||
if (odooEditorHtml && targetSupportsHtmlContent) {
|
||||
if (!targetSupportsHtmlContent) {
|
||||
const text = ev.clipboardData.getData("text/plain");
|
||||
this._applyCommand("insert", text);
|
||||
} else if (odooEditorHtml) {
|
||||
const fragment = parseHTML(this.document, odooEditorHtml);
|
||||
// Instantiate DOMPurify with the correct window.
|
||||
this.DOMPurify ??= DOMPurify(this.document.defaultView);
|
||||
@@ -4792,7 +4796,7 @@ export class OdooEditor extends EventTarget {
|
||||
if (fragment.hasChildNodes()) {
|
||||
this._applyCommand('insert', fragment);
|
||||
}
|
||||
} else if ((files.length || clipboardHtml) && targetSupportsHtmlContent) {
|
||||
} else if (files.length || clipboardHtml) {
|
||||
const clipboardElem = this._prepareClipboardData(clipboardHtml);
|
||||
// When copy pasting a table from the outside, a picture of the
|
||||
// table can be included in the clipboard as an image file. In that
|
||||
|
||||
Reference in New Issue
Block a user