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 34d39edd511..6571ad1209a 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 @@ -539,8 +539,14 @@ export const editorCommands = { } else { font = []; } - } else if (node.nodeType === Node.TEXT_NODE && isVisibleStr(node)) { - // Node is a visible text node: wrap it in a . + } else if ((node.nodeType === Node.TEXT_NODE && isVisibleStr(node)) + || (node.nodeType === Node.ELEMENT_NODE && + ['inline', 'inline-block'].includes(getComputedStyle(node).display) && + isVisibleStr(node.textContent) && + !node.classList.contains('btn') && + !node.querySelector('font'))) { + // Node is a visible text or inline node without font nor a button: + // wrap it in a . const previous = node.previousSibling; const classRegex = mode === 'color' ? BG_CLASSES_REGEX : TEXT_CLASSES_REGEX; if ( diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/editor.test.js b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/editor.test.js index 2098ad89156..37fa81d9b61 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/editor.test.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/editor.test.js @@ -5658,6 +5658,22 @@ X[] }); }); }); + it('should apply a color to a slice of text containing a span', async () => { + await testEditor(BasicEditor, { + contentBefore: '

a[bcd]e

', + stepFunction: editor => editor.execCommand('applyColor', 'rgb(255, 0, 0)', 'color'), + contentAfter: '

a[bcd]e

', + }); + }); + it('should distribute color to texts and to button separately', async () => { + await testEditor(BasicEditor, { + contentBefore: '

a[bcd]e

', + stepFunction: editor => editor.execCommand('applyColor', 'rgb(255, 0, 0)', 'color'), + contentAfter: '

a[b' + + 'c' + + 'd]e

', + }); + }); }); describe('markdown', () => {