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 afd12883869..ae81acab42a 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 @@ -532,7 +532,7 @@ export const editorCommands = { node => closestElement(node).isContentEditable ); let coloredTds = []; - if (selectedTds.length) { + if (selectedTds.length && mode === "backgroundColor") { for (const td of selectedTds) { colorElement(td, color, mode); } @@ -555,7 +555,9 @@ export const editorCommands = { if (isEmptyBlock(range.endContainer)) { selectionNodes.push(range.endContainer, ...descendants(range.endContainer)); } - const selectedNodes = selectionNodes.filter(node => !closestElement(node, 'table.o_selected_table')) + const selectedNodes = mode === "backgroundColor" + ? selectionNodes.filter(node => !closestElement(node, 'table.o_selected_table')) + : selectionNodes; const fonts = selectedNodes.flatMap(node => { let font = closestElement(node, 'font') || closestElement(node, 'span'); const children = font && descendants(font); diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/color.test.js b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/color.test.js index c31cd4c4d9e..3d8299794e3 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/color.test.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/color.test.js @@ -55,7 +55,7 @@ describe('applyColor', () => { it('should apply a background color on empty selection', async () => { await testEditor(BasicEditor, { contentBefore: '
[
]
[\u200B
' + '\u200B
' + ']\u200B
', @@ -97,7 +97,7 @@ describe('applyColor', () => {| []ab |
| a]b | ' + - 'cd | ' + - 'ef | ' + - '
a[bc
+| a]b | +cd | +ef | +
a[bc
' + - '| a]b | ' + - 'cd | ' + - 'ef | ' + - '
+ a[bc +
+| + a]b + | ++ cd + | ++ ef + | +
a]bc
', stepFunction: async editor => editor.execCommand('applyColor', 'aquamarine', 'color'), - contentAfterEdit: '| ab | ' + - 'cd | ' + - 'e[f | ' + - '
a]bc
', + contentAfterEdit: unformat(` +| + ab + | ++ cd + | ++ e[f + | +
+ a]bc +
`), }); }); it('should apply a color to some characters, a table and some more characters', async () => { @@ -5224,13 +5254,26 @@ X[] '' + 'a]bc
', stepFunction: async editor => editor.execCommand('applyColor', 'aquamarine', 'color'), - contentAfterEdit: 'a[bc
' + - '| ab | ' + - 'cd | ' + - 'ef | ' + - '
a]bc
', + contentAfterEdit: unformat(` ++ a[bc +
+| + ab + | ++ cd + | ++ ef + | +
+ a]bc +
`), }); }); it('should apply a color to some characters, a table, some more characters and another table', async () => { @@ -5248,18 +5291,39 @@ X[] 'a[bc
' + - '| ab | ' + - 'cd | ' + - 'ef | ' + - '
abc
' + - '| a]b | ' + - 'cd | ' + - 'ef | ' + - '
+ a[bc +
+| + ab + | ++ cd + | ++ ef + | +
+ abc +
+| + a]b + | ++ cd + | ++ ef + | +
a]bc
', stepFunction: async editor => editor.execCommand('applyColor', 'aquamarine', 'color'), - contentAfterEdit: 'a[bc
' + - '| ab | ' + - 'cd | ' + - 'ef | ' + - '
abc
' + - '| ab | ' + - 'cd | ' + - 'ef | ' + - '
a]bc
', + contentAfterEdit: unformat(` ++ a[bc +
+| + ab + | ++ cd + | ++ ef + | +
abc
+| + ab + | ++ cd + | ++ ef + | +
a]bc
`), }); }); }); @@ -5554,11 +5637,18 @@ X[] '| a[b | ' + - 'c]d | ' + - 'ef | ' + - '
| + a[b + | ++ c]d + | +ef | +
| a[b | ' + - 'cd | ' + - 'e]f | ' + - '
| ab | cd | ef |
| + a[b + | ++ cd + | ++ e]f + | +
| ab | +cd | +ef | +
| a[b | ' + - 'cd | ' + - 'ef | ' + - '
| ab | ' + - 'cd | ' + - 'ef | ' + - '
| a]b | ' + - 'cd | ' + - 'ef | ' + - '
| + a[b + | +cd | +ef | +
| + ab + | +cd | +ef | +
| + a]b + | +cd | +ef | +
| a[b | ' + - 'cd | ' + - 'ef | ' + - '
| ab | ' + - 'c]d | ' + - 'ef | ' + - '
| ab | ' + - 'cd | ' + - 'ef | ' + - '
| + a[b + | ++ cd + | +ef | +
| + ab + | ++ c]d + | +ef | +
| ab | +cd | +ef | +
| a[b | ' + - 'cd | ' + - 'ef | ' + - '
| ab | ' + - 'cd | ' + - 'ef | ' + - '
| ab | ' + - 'cd | ' + - 'e]f | ' + - '
| + a[b + | ++ cd + | ++ ef + | +
| + ab + | ++ cd + | ++ ef + | +
| + ab + | ++ cd + | ++ e]f + | +