diff --git a/addons/web_editor/static/src/js/backend/convert_inline.js b/addons/web_editor/static/src/js/backend/convert_inline.js index 5db9c3e9ed1..0c8af9a8e45 100644 --- a/addons/web_editor/static/src/js/backend/convert_inline.js +++ b/addons/web_editor/static/src/js/backend/convert_inline.js @@ -289,13 +289,14 @@ function cardToTable($editable) { * @param {Object} cssRules */ function classToStyle($editable, cssRules) { + const writes = []; _applyOverDescendants($editable[0], function (node) { const $target = $(node); const css = _getMatchedCSSRules(node, cssRules); // Flexbox for (const styleName of node.style) { if (styleName.includes('flex') || `${node.style[styleName]}`.includes('flex')) { - node.style[styleName] = ''; + writes.push(() => { node.style[styleName] = ''; }); } } // Ignore font-family (mail-safe font declared in ) @@ -313,30 +314,33 @@ function classToStyle($editable, cssRules) { } }; if (_.isEmpty(style)) { - $target.removeAttr('style'); + writes.push(() => { $target.removeAttr('style'); }); } else { - $target.attr('style', style); - } - if ($target.get(0).style.width) { - $target.attr('width', $target.css('width')); // Widths need to be applied as attributes as well. + writes.push(() => { + $target.attr('style', style); + if ($target.get(0).style.width) { + $target.attr('width', $target.css('width')); + } + }); } // Media list images should not have an inline height if (node.nodeName === 'IMG' && $target.hasClass('s_media_list_img')) { - $target.css('height', ''); + writes.push(() => { $target.css('height', ''); }); } // Apple Mail if (node.nodeName === 'TD' && !node.childNodes.length) { - $(node).append(' '); + writes.push(() => { $(node).append(' '); }); } // Outlook if (node.nodeName === 'A' && $target.hasClass('btn') && !$target.hasClass('btn-link') && !$target.children().length) { - $target.prepend(``); - $target.append(``); + writes.push(() => { $target.prepend(``); }); + writes.push(() => { $target.append(``); }); } else if (node.nodeName === 'IMG' && $target.is('.mx-auto.d-block')) { - $target.wrap('

'); + writes.push(() => { $target.wrap('

'); }); } }); + writes.forEach(fn => fn()); } /** * Convert the contents of an editable area (as a JQuery element) into content