From 1b15f8c1a7210ce264e9e2725e1be900dc3f01b7 Mon Sep 17 00:00:00 2001 From: Nicolas Bayet Date: Thu, 8 Sep 2022 12:03:06 +0000 Subject: [PATCH] [FIX] web_editor: prevent creating a link when it already exists Before this commit The method `getOrCreateLink` did not return the startNode when the startNode was a link. If the startNode is a link, we should not try to get the link from the selection as we already have the link. Getting the link from the selection should be a fallback. When clicking on a link that within a `contenteditable=false`, because the link startNode was not returned, the element from the selection was not the link and `getOrCreateLink` created a new link. task-2967314 closes odoo/odoo#99864 X-original-commit: c50c2b025c58408b2e90b7b25430c981d0bcdc2b Signed-off-by: David Monjoie (dmo) --- .../web_editor/static/src/js/wysiwyg/widgets/link.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/addons/web_editor/static/src/js/wysiwyg/widgets/link.js b/addons/web_editor/static/src/js/wysiwyg/widgets/link.js index a19224780c1..e5bd1109470 100644 --- a/addons/web_editor/static/src/js/wysiwyg/widgets/link.js +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/link.js @@ -502,9 +502,13 @@ const Link = Widget.extend({ */ Link.getOrCreateLink = ({ containerNode, startNode } = {}) => { - if (startNode && !$(startNode).is('a')) { - $(startNode).wrap(''); - return { link: startNode.parentElement, needLabel: false }; + if (startNode) { + if ($(startNode).is('a')) { + return { link: startNode, needLabel: false }; + } else { + $(startNode).wrap(''); + return { link: startNode.parentElement, needLabel: false }; + } } const doc = containerNode && containerNode.ownerDocument || document;