[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) <dmo@odoo.com>
This commit is contained in:
Nicolas Bayet
2022-09-09 11:12:49 +02:00
parent d8f1b8deda
commit 1b15f8c1a7
@@ -502,9 +502,13 @@ const Link = Widget.extend({
*/
Link.getOrCreateLink = ({ containerNode, startNode } = {}) => {
if (startNode && !$(startNode).is('a')) {
$(startNode).wrap('<a href="#"/>');
return { link: startNode.parentElement, needLabel: false };
if (startNode) {
if ($(startNode).is('a')) {
return { link: startNode, needLabel: false };
} else {
$(startNode).wrap('<a href="#"/>');
return { link: startNode.parentElement, needLabel: false };
}
}
const doc = containerNode && containerNode.ownerDocument || document;