From 364be6ebada6d97733412fb4326410d4eb2cf9a8 Mon Sep 17 00:00:00 2001 From: "Antoine (ande)" Date: Mon, 16 Oct 2023 10:07:37 +0000 Subject: [PATCH] [FIX] web_editor: traceback when changing color Current behaviour: When coloring a word multiple colors, then wanting to re-color it a unified color, there is a traceback. Steps to reproduce: 1. Go to Settings 2. Click on Configure Document Layout 3. In Company Details, select a word 4. (eg: YourCompany) 5. Color half in yellow and half in red 6. (eg: Your in yellow, Company in red) 7. Then select the whole word 8. Color it in a unified color (eg: black) 9. Traceback Cause of the issue: range.setEnd(...endPos(last)) was throwing a warning: During applyColor, Sanitize is called, which merges similar nodes. (using moveNodes) After the merge, out of n similar nodes, only the first one is still contained in the document. opw-3502124 closes odoo/odoo#144619 X-original-commit: 43a5aec38809f3e7e29b278704fc2143d6cc236e Signed-off-by: Nicolas Bayet (nby) Signed-off-by: Antoine Demany (ande) --- addons/web_editor/static/src/js/wysiwyg/wysiwyg.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index 3aa283f28ed..ecd3099967b 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -1974,7 +1974,9 @@ export class Wysiwyg extends Component { if (color && !isCSSColor(color) && !weUtils.isColorGradient(color)) { color = (colorType === "text" ? 'text-' : 'bg-') + color; } - const coloredElements = this.odooEditor.execCommand('applyColor', color, colorType === 'text' ? 'color' : 'backgroundColor', this.lastMediaClicked); + let coloredElements = this.odooEditor.execCommand('applyColor', color, colorType === 'text' ? 'color' : 'backgroundColor', this.lastMediaClicked); + // Some nodes returned by applyColor can be removed of the document by the sanitization in historyStep + coloredElements = coloredElements.filter(element => this.odooEditor.document.contains(element)); const coloredTds = coloredElements && coloredElements.length && Array.isArray(coloredElements) && coloredElements.filter(coloredElement => coloredElement.classList.contains('o_selected_td')); if (coloredTds.length) {