From 3ef5004c13ef57d27dd09881a6636bb0fbdac00f Mon Sep 17 00:00:00 2001 From: Benoit Socias Date: Tue, 19 Oct 2021 14:45:32 +0000 Subject: [PATCH] [FIX] web_editor: merge inline elements into previous color font Before this commit when a color was applied on a text that spans several nodes, it was wrapping each text node in a font node to which the color was applied. Because of this, applied gradient colors were restarting on each text part. (e.g. before a bold section, on the bold section, after the bold section: each had a distinctly drawn gradient) After this commit the bold and italic nodes are considered similar to text nodes and are wrapped inside a common font node to which the color is applied - using the mechanism that already existed for text nodes. Actually applied on all visible inline & inline-block elements that do not contain a font node (and are not buttons). task-2666200 closes odoo/odoo#109537 X-original-commit: 8c965cad4d3fdbfefbbd5caa43d8c21e3a8e064f Signed-off-by: Arthur Detroux (ard) Signed-off-by: Benoit Socias (bso) --- .../editor/odoo-editor/src/commands/commands.js | 10 ++++++++-- .../editor/odoo-editor/test/spec/editor.test.js | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) 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', () => {