diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index c6c696daf73..eac69e4a907 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -1400,7 +1400,17 @@ const Wysiwyg = Widget.extend({ } if (params.node) { - params.node.replaceWith(element); + const isIcon = (el) => el.matches('i.fa, span.fa'); + const changedIcon = isIcon(params.node) && isIcon(element); + if (changedIcon) { + // Preserve tag name when changing an icon and not recreate the + // editors unnecessarily. + for (const attribute of element.attributes) { + params.node.setAttribute(attribute.nodeName, attribute.nodeValue); + } + } else { + params.node.replaceWith(element); + } this.odooEditor.unbreakableStepUnactive(); this.odooEditor.historyStep(); } else {