From 63fa6dd45d3e03b1df17839114f0b50297b08dde Mon Sep 17 00:00:00 2001 From: "Mahdi Cheikh Rouhou (macr)" Date: Thu, 22 Feb 2024 13:31:52 +0100 Subject: [PATCH] [FIX] web_editor: conserve changes on edit link label Issue: ====== When you update the link button label from the sidebar it loses its style. Steps to reproduce the issue: ============================= - Got to website editor - Insert a text block - Added a button in the text block and any label - Click on the button to edit it from the sidebar - Change font size or font color or any style you want - Update the label - The style is lost Origin of the issue: ==================== When updating the label, we search for the first child that has that text, but when we have `ZWS start` it will be considered as the first child and then we update the inner text of the `a` element so we loose the span of the text which has the custom styles. Solution: ========= We search for the first child which is not `ZWS` task-3721686 closes odoo/odoo#157758 X-original-commit: 999d5787e3d8d0518692f987341dd6b298d7ffc4 Signed-off-by: Antoine Guenet (age) --- .../static/src/js/wysiwyg/widgets/link.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 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 4fb94380139..aebf0032d4d 100644 --- a/addons/web_editor/static/src/js/wysiwyg/widgets/link.js +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/link.js @@ -475,13 +475,17 @@ export class Link extends Component { $link.html(this.state.originalHTML); } else if (linkInfos.content && linkInfos.content.length) { let contentWrapperEl = $link[0]; - // Update the first child element that has the same inner text + const text = $link[0].innerText.replaceAll("\u200B", "").trim(); + // Update the first not ZWS child element that has the same inner text // as the link with the new content while preserving child // elements within the link. (e.g. the link is bold and italic) - while (contentWrapperEl.firstElementChild - && (contentWrapperEl.firstElementChild.innerText === $link[0].innerText)) { - contentWrapperEl = contentWrapperEl.firstElementChild; - } + let child; + do { + contentWrapperEl = child || contentWrapperEl; + child = [...contentWrapperEl.children].find( + (element) => !element.hasAttribute("data-o-link-zws") + ); + } while (child?.innerText.replaceAll('\u200B', '').trim() === text); contentWrapperEl.innerText = linkInfos.content; } else { $link.text(linkInfos.url);