diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/commands.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/commands.js index 37569552728..3e750c6d194 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/commands.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/commands.js @@ -433,14 +433,23 @@ export const editorCommands = { textAlignStyles.set(block, block.style.textAlign); } }); + // Calling `document.execCommand` will cause an input event with the + // input type "formatRemove". This would cause a new history step to be + // created in the middle of the process, which we prevent here. + editor.historyPauseSteps(); editor.document.execCommand('removeFormat'); for (const node of getTraversedNodes(editor.editable)) { - // The only possible background image on text is the gradient. - closestElement(node).style.backgroundImage = ''; + if (node.nodeType === Node.ELEMENT_NODE && node.hasAttribute('color')) { + node.removeAttribute('color'); + } + const element = closestElement(node); + element.style.removeProperty('color'); + element.style.removeProperty('background'); } textAlignStyles.forEach((textAlign, block) => { block.style.setProperty('text-align', textAlign); }); + editor.historyUnpauseSteps(); }, // Align diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/format.test.js b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/format.test.js index 97dbaa0652f..7a3e25086b0 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/format.test.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/format.test.js @@ -949,6 +949,34 @@ describe('Format', () => { contentAfter: '
[ab]